Recently, many projects developed by the company require cross-domain ajax requests, such as several sub-domain names
http://a.****.com/index123.aspx,
http://b .****.com/index2.aspx
must request the user’s json information and then process the data. At first, my colleagues and I tried many methods, using $.ajax() whether The get or post methods will cause uri deny errors. After some GG, I found the solution and understood the reason.
Starting from jquery 1.2, .getJSON supports cross-domain operations. Cross-domain problems can be solved using the jquery.getJSON() method. The example is as follows
Front desk
JS code in HTML
function gettst2() {
$.getJSON("http://ucenter.xxxx.com.cn/ajax/test.aspx?callback=?", { id: "123456", site: "01" },
function(data) {
alert(data.htmls);
document.getElementById("shows").innerHTML = data.htmls;
});
}
gettst2();
The processing in the ASPX.cs file is
string jsoncall = Request.QueryString("callback");
Response.Write(jsoncall + "({htmls:test001} )");
If you add html code, be sure not to add the /n symbol, otherwise garbled codes and js errors will occur.
For more jquery ajax cross-domain solutions (json method) related articles, please pay attention to the PHP Chinese website!