The example in this article describes how jquery ajax implements cross-domain requests. Share it with everyone for your reference. The specific implementation method is as follows:
Note: The dataType here is "jsonp"; type can only be GET
The front desk request 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) {
//Handling errors
}
});
The background processing code ValidAccountsExists.aspx 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 be helpful to everyone’s jQuery programming.