because AJAX requests do not support cross-domain, there is a problem with multiple domain names interacting. The principle of cross-domain is this, the SRC attribute in HTML request the address can be cross-domain, for example and <script>For example, test.js in Test ({name:'Meigong', Sex:'Mans'}); in index.html<script >function test (data) {alert ('Name:'+data.name+"Gender:"+data.sex); } </script> <script src='Http://www.biuman.comt/test/test.js'></script>This time will pop box, jailbreak success! Here is a package, the callback function name passed past imitation Baidu<script>//callback functionfunction Test (a) {alert (a.name); } setTimeout (function () {varURL ="http://www.biuman.com/test/jsonp/test.php?cb=test"; varScript =document.createelement ('Script'); Script.setattribute ('src', URL); document.getElementsByTagName ("Body")[0].appendchild (script); }, -); </script >test.php<?php $filename='./su'; $fun= $_get['CB']; $arr=Array ('name'='Meigong', 'Sex'='Mans' ); $res=Json_encode ($arr); $res= $fun." (". $res.")"; File_put_contents ($filename, $res); Header ('content-type:biuman/test'); Header ('content-disposition:attachment; filename='. $filename);//download mode, Firebug in the network in response to not see the contentReadFile"$filename"); Exit (); ? >In addition, jquery encapsulates the Jsonp<script >$ (function () {$.ajax ({URL:"http://www.biuman.com/test/jsonp/test.php", DataType:"Jsonp", Jsonp:"CB",// //The parameter name that is passed to the request handler or page to obtain the name of the JSONP callback function (generally by default: callback)Jsonpcallback:"Test",//Required callback functionsuccess:function (data) {alert (data.name); }, Error:function () {alert ('Network Exceptions'); } }); }) </script >
<script type= "Text/javascript" src= "Http://sources.ikeepstudying.com/js/jquery-1.8.3.min.js" ></script >
<script type= "Text/javascript" >
$.getjson ("http://test.ikeepstudying.com/json.php?callback=?",
function (Result) {
for (var i in result) {
Alert (i+ ":" +result[i]);//loop output a:1,b:2,etc.
}
});
</script>
JSONP cross-domain