Backend:
Copy codeThe Code is as follows:
<? Php
$ Json_str = json_encode (array ("ddd" => "11111111 "));
Echo $ _ GET ['ja '].' ('. $ json_str .')';
?>
Front end:
Copy codeThe Code is as follows:
$. GetJSON ('HTTP: // www.liushan.cn/test.php? Ja =? ', Function (json ){
Alert (json );
});
Pure JS implementation (JSONP ):
Copy codeThe Code is as follows:
// Server return aa ({'ddd ': 'ddd'}) callback function name: $ _ GET ['callback']
// Author: lonely
(Function (w ){
Function getjson (){}
Getjson. prototype. set = function (url, callback, callbackname ){
This. callfn = callbackname | 'urlcallback ';
This. url = url + "? Callback = "+ this. callfn;
Try {
Eval (this. callfn + "= function (data) {\ n" +
"Callback (data); \ n" +
'Delete' + this. callfn + ';}');
} Catch (e) {return ;}
This. request ();
Delete this. url;
}
Getjson. prototype. request = function (){
Var script = document. createElement ("script ");
Script. src = this. url;
Var load = false;
Script. onload = script. onreadystatechange = function (){
If (this. readyState = "loaded" | this. readyState = "complete "){
Load = true;
Script. onload = script. onreadystatechange = null;
}
};
Var head = document. getElementsByTagName ("head") [0];
Head. insertBefore (script, head. firstChild );
}
W. getjson = getjson;
}) (Window)
// Use DOME
New getjson (). set ("http://www.test.cn/test.php", function (data ){
Alert (data. ddd );
});
Another: getScript
Copy codeThe Code is as follows:
JQuery. getScript ("http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js", function (){
$ ("# Go"). click (function (){
$ (". Block"). animate ({backgroundColor: 'pink'}, 1000)
. Animate ({backgroundColor: 'blue'}, 1000 );
});
}); // CHM Help File example