SoFunction
Updated on 2025-03-09

Work with jQuery to solve cross-domain calls

1. Call using JSONp

Without detailed explanation, you can refer to the jq document "jQuery 1.10.3 Online Manual

2. Server configuration

Modify the file

<>
  <modules runAllManagedModulesForAllRequests="true"></modules>
  <httpProtocol>
   <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*"/>
    <add name="Access-Control-Allow-Headers" value="Content-Type"/>
    <add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE"/>
   </customHeaders>
  </httpProtocol>
</>

The client call code is as follows

var param = {};
var msg = "dafdasfdsaf";
param["userName"] = "1";
param["passWord"] = "1";
param["code"] = "3323";
$.ajax({
  url: "/UserAjax/Login?t=" + (),
  data: param,
  type: "post",
  async:false,
  success: function (result) {
    alert(result);
    msg = result;
  }
});
alert(msg+"ddddddddddFFFFFFFFFFFFFFFF");

After the test call is successful, it can be used for call on the mobile phone.

The above article cooperates with jQuery to solve the problem of cross-domain calls is all the content I share with you. I hope you can give you a reference and I hope you can support me more.