JQuery cross-Domain method recommendation _ can be _jquery across any website

Source: Internet
Author: User

Due to find a lot of Bo friends in the park SMS asked JS cross domain problem, I think a lot of programmers in the mind also think that JS is not cross-domain, in fact, this is a wrong point of view; there are a lot of people on the Internet to find their solution, teaching its use of IFRAME to solve a lot of articles, really so complicated? In fact it's very simple, if you use jquery, a Getjson method is done, and a line of code is done.

Here's how to start sticking out.

Cross-domain (across all domain names)
    $.getjson ("http://user.hnce.com.cn/getregion.aspx?id=0&jsoncallback=?", function (JSON) {
     
     //requires the data format of the remote request page to be:? (Json_data) 
     For example:
     //? ( [{"_name": "Hunan Province", "_regionid": 134},{"_name": "Beijing", "_regionid": 143}])
     alert (json[0]._name);

     });

Note that in getregion.aspx, when outputting JSON data, be sure to use request.querystring["Jsoncallback" to put what gets in front of the returned JSON data, assuming the actual fetch value is 42342348, Then the return value is 42342348 ([{"_name": "Hunan Province", "_regionid": 134},{"_name": "Beijing", "_regionid": 143}])

Because Getjson is the principle of the cross domain? Randomly changing a method name, and then returning the execution to achieve the goal of cross-domain response.

For specific Getjson instructions, please refer to the jquery manual.

The following is a real example of cross-domain execution:

Code highlighting produced by Actipro Codehighlighter (freeware)
http://www. codehighlighter.com/

--><script src= "http://common.jb51.net/script/jquery.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
//Cross-domain (can be across all domain names)
  $.getjson ("http:// E.hnce.com.cn/tools/ajax.aspx?jsoncallback=? ", {id:0, action: ' Jobcategoryjson '}, function (JSON) {

    alert (json[0 ].PID);
    alert (json[0].items[0]._name);

  });
</script>

Above this jquery Cross-domain method recommendation _ can cross any website is small series to share to everybody's content, hoped can give everybody a reference, also hoped that everybody supports the cloud habitat community.

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.