Many of the projects recently developed by the company require Cross-domain AJAX requests, such as several sub domains
Http://a.****.com/index123.aspx,
Http://b.****.com/index2.aspx
To request the user JSON information, and then to process the data, at first I and my colleagues tried a number of ways, using $.ajax () either a Get or post method will cause the URI deny error. GG After found the solution, but also understand the reasons.
jquery starts with 1.2, and the. Getjson supports Cross-domain operations. Use the Jquery.getjson () method to resolve cross-domain problems. Examples are as follows
Front desk
<script type= "Text/javascript" src= "/script/jquery.js" ></script>
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 ASPX.cs file is processed as
String jsoncall = Request.QueryString ("callback");
Response.Write (Jsoncall + "({htmls: Test 001})");
If add HTML code, do not add/n symbol, otherwise will appear garbled, JS error.