Jquery ajax cross domain solution method of json


Many of the recent projects developed by the company require cross-domain ajax requests, such as under several subdomains http://a. * * * *. Com/index123. Aspx, http://b. * * * *. Com/index2. Aspx

My colleagues and I first tried a number of ways to request the user’s json information and then process the data. Using $.ajax() either the get or post methods caused the uri deny error. After a while GG discovered the solution, also understand among them reason.

**The front desk **< Script type = “text/javascript” SRC = ”/ script/jquery. Js” > < / script>

**JS code in HTML **The function gettst2 () {       $. GetJSON (” http://ucenter.xxxx.com.cn/ajax/test.aspx? The callback =?” , {id: “123456”, site: “01”}, The function (data) {       Alert (data. HTMLS);         Document. The getElementById (” shows ”). The innerHTML = data. The HTMLS; }); } Gettst2 ();

**In the aspx.cs file **String jsoncall = Request. The QueryString (” callback ”); Response.write (jsoncall + ”({HTMLS: test 001})”);

If you add HTML code, do not add /n symbol, or there will be messy code, js error.