Home >Web Front-end >JS Tutorial >jquery ajax method to implement cross-domain requests_jquery

jquery ajax method to implement cross-domain requests_jquery

WBOY
WBOYOriginal
2016-05-16 16:19:061117browse

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:

Copy code The 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:


Copy code The 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 be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn