Introduction to jquery Ajax cross-domain approach

Source: Internet
Author: User

In this article, as long as the jquery Ajax Cross-domain Solution (JSON method) is introduced, the need for friends can come to the reference, I hope to help you

Recently, many of the projects developed by the company require Cross-domain AJAX requests, such as http://a.****.com/index123.aspx under several subdomains, http://b.****.com/index2.aspx requesting user JSON information, And then processing 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 the following foreground <script type= "Text/javascript" src= "/script/jquery.js" ></script> HTML JS code function gettst2 () { $.getjson ("http://ucenter.xxxx.com.cn/ajax/test.aspx?callback=?", {ID: "123456", Site: "}", function (data) {Ale      RT (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.

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.