Jquery + ajax method for implementing cross-origin requests, jqueryajax
This example describes how to implement cross-origin requests using jquery + ajax. Share it with you for your reference. The specific implementation method is as follows:
Note:The ype here is "jsonp"; type can only be GET
The front-end request code is as follows:
Copy codeThe Code is as follows: $. ajax ({
Type: "GET ",
Url: "http://www.xxx.com/Rest/ValidAccountsExists.aspx? Accounts = admin ",
DataType: "jsonp ",
Jsonp: "jsoncallback ",
Success: function (result ){
Alert (result. Success );
Alert (result. Content );
},
Error: function (result, status ){
// Handle errors
}
});
The background processing code ValidAccountsExists. aspx is as follows:
Copy codeThe Code is as follows: string accounts = GameRequest. GetQueryString ("accounts ");
String jsoncallback = GameRequest. GetQueryString ("jsoncallback ");
Response. ContentEncoding = System. Text. Encoding. UTF8;
Response. ContentType = "application/json ";
Response. write (jsoncallback + "({\" Success \ ": \" True \ ", \" Content \ ": \" "+ accounts + "\"})");
Response. End ();
I hope this article will help you with jQuery programming.