ASP. NET and jQuery to solve the problem of cross domain call
- 2021-08-03 09:52:12
- OfStack
1. Use JSONp to call
For no detailed explanation, please refer to the jq document "jQuery 1.10. 3 Online Manual"
2. Server-side configuration
Modify the Web. config file
<system.webServer>
<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>
</system.webServer>
The client call code is as follows
var param = {};
var msg = "dafdasfdsaf";
param["userName"] = "1";
param["passWord"] = "1";
param["code"] = "3323";
$.ajax({
url: "http://www.ts-wms.com/UserAjax/Login?t=" + Math.random(),
data: param,
type: "post",
async:false,
success: function (result) {
alert(result);
msg = result;
}
});
alert(msg+"ddddddddddFFFFFFFFFFFFFFFF");
After testing, the call is successful, and it can be used for mobile phone call.