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.