jquery Ajax Cross-domain Workaround (JSON method) _jquery

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.