1. 程式人生 > >Asp.Net操作WebServices(ajax)

Asp.Net操作WebServices(ajax)

logs scrip 跨域 script ons system str tps post

https://www.cnblogs.com/litianci/p/4909689.html

https://segmentfault.com/a/1190000012469713?utm_source=tag-newest

前端jquery:

$(document).ready(function () {
    //alert(1);
    $.ajax({
        type: "post", //訪問WebService使用Post方式請求
        url: "http://192.168.2.246/xxxxxxx/GetProcodeEcharts",//WebService的地址和方法名稱組合
        data: ‘{"Account":"jfyh"}‘, //參數
        contentType: "Application/Json", // 編碼類型
        success: function (data) {
            //alert(2);
            str = JSON.stringify(data)
            alert(str);
        }
    });
});

 跨域問題:

在Web.config配置文件中添加
 <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="chrome=1" />
		
		<add name="Access-Control-Origin" value="*" />
		<add name="Access-Control-Allow-Origin" value="*" />
		
		<add name="Access-Control-Headers" value="X-Requested-With,Content-Type,Accept,Origin" />
		<add name="Access-Control-Allow-Headers" value="X-Requested-With,Content-Type,Accept,Origin" />
		
		<add name="Access-Control-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
		<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS"/>
</system.webServer>

  

Asp.Net操作WebServices(ajax)