跨域请求域有两种常用解决方案,jsonp和cors,

因为jsonp只能解决get请求问题,我这里用的是cors方法。

js前端ajax请求:

$.ajax({ url: "http://192.168.0.43:9030/Home/GetTextValue", //需要请求的路径(注意,部署的时候放在不同的电脑上面,要不然你的只是跨端口而不是跨域)

data: { },

type: "post",

//async: false,

dataType: "json",

success: function (data){

$("#kua").html(data.info) },

error: function (data) {

console.log("获取识别结果失败,请重试!"); }

});

 

(需要跨的项目)资源项目的web里面配置文件

<system.webServer>

<httpProtocol>
<customHeaders>
<!--可以访问此域资源的域。*为所有-->
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin,Content-Type, Accept,Authorization,X-Requested-With" />
<!--可以访问此域的脚本方法类型 -->
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>

 

 

 

相关文章:

  • 2022-01-23
  • 2021-05-29
  • 2021-10-23
猜你喜欢
  • 2022-02-11
  • 2021-12-19
  • 2021-12-19
  • 2021-03-31
  • 2021-05-30
  • 2021-07-31
相关资源
相似解决方案