Cross-origin jquery ajax Solution

Source: Internet
Author: User

As long as this article introduces jquery ajax cross-origin solution (json mode), you can refer to it for help.

Cross-origin ajax requests are required in many projects recently developed by the company, for example, http: //. ****. com/index123.aspx, http: // B. ****. com/index2.aspx requests the json information of the user and then processes the data. At first, my colleagues and I tried many methods, using $. ajax (), whether it is get or post, will cause uri deny errors. Some GG later found the solution and understood the reasons. Since jquery 1.2,. getJSON supports cross-origin operations. The jquery. getJSON () method can be used to solve cross-origin problems. Example: <script type = "text/javascript" src = "/script/jquery. js "> </script> function gettst2 () {$. getJSON ("http://ucenter.xxxx.com.cn/ajax/test.aspx? Callback =? ", {Id:" 123456 ", site:" 01 "}, function (data) {alert(data.html s); document. getElementById ("shows "). innerHTML = data.html s;}) ;}gettst2 (); ASPX. the cs file is processed as string jsoncall = Request. queryString ("callback"); Response. write (jsoncall + "({htmls: Test 001})"); If html code is added, do not add the/n symbol. Otherwise, garbled characters and js errors may occur.

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.