?? ?? JSONP? ?? ?? JSONP? ??? ??? ??????? JSONP?
????? ????? ???? ???????? ?? ???? ??? ???????? ?????? ??? ???????? (??? ?? ??? ????? ???????? ??????? ????????? ?? ????? ???????? ???????? ?? ??????? ????????) ?? ?? ??? ??? ?????? ???????? ?? ???? ????? ???????. ??? ???? ??????? ?? ???? ????? crossdomain.xml ?? ?? ???? ??? ????? ?? ??? HTTP.
??? crossdomain.xml ????? ??????? ??????? ??????? ??? ???? ????????? ????? ??????? ????? ???? ????? ????.
??? ????? ??? jsonp ?? ?????? ??????? ?????? ??? ???? ?????? ????? ???????? ??????? ??? ???????? ?? ??? ???????.
jsonp ?? ???? ??????? ???? ?????????.
?? ???? ?????? ??? ??? ?????? js ?? ????? ??? ????? ??? js ?? ??? ?????? ????? ??????? ??? ?????.
??????? ???????? ?? js ?????? ????????? ???????? javascript ???? ??? ??????? ?? ??????? ??????????? (jsp? php? aspx) ??? ??? ???????.
function showjson(json){
alert(json.url);
}
如果引用的js或動(dòng)態(tài)頁(yè)面里有 showjson({"url":" http://www.foxrdc.com "});這行代碼的話(huà),那就會(huì )彈出 http://www.foxrdc.com
????? ???? ??? ?? ??? ??????. http://www.ibilibili.com/static/js/forbejson/userinfo.php ?????? ??????? ?????? ??? ?????? php ??? ???? ?? ???? showjson? ???????? ???? showjson ???????? ?? ?????? bejson ?????? json ?????:
< ?php
// ??? ?? ???? PHP? ??? ??????? ???? showjson? ???? ?? ?????? ??? ?????? ?? ???? ????????? ??????? ?? ?????? ??????? ?????.
echo 'showjson({"url":"http://www.foxrdc.com"})';
?>
??? ???? ??????? ?? PHP:
$("#getuserp").click(function(){
$.getScript("http://www.foxrdc.com/test/userinfop.php");
});
??? ???? ??????? ????? ??? ???? ???? (??? ?? ???? ?? ?????? ?????)? ??? ????? ??? ????? ?? ????? ??? HTTP.
???? www.foxrdc.com/test/userinfop.php ?????
頁(yè)面里輸出了 showjson({"url":" http://www.foxrdc.com "}) ,
????? ?????? ?? ?????? ??? ??? ??? ???? ?????? ???? ????? ?????? ??????? ????? showjson ??????? (???? ????? ??????) ?????? ?????? json (???? ????? ??????)? ???????? ????? ????? url ??????? ?? json.
?????
???
??? ??? ?? ????? ???? ????? ??????.
?x $.ajax({
? ? url:'//www.foxrdc.com/test/userinfop.php',
? ? type:"GET",
? ? ? ? ? ?dataType:"jsonp",
? ? ? ? ? ?jsonp: false,
? ? ? ? ? ?jsonpCallback: "showjson", // ??? ?? ???? ?????? ??? ?????? ???? ???? ?????????.
? ? ? ? ? ?success:function(data){
? ? ? ? ? ? ? ?console.log("Script loaded and executed.");
? ? ? ? ? },
? ? ? ? ? ?error:function (textStatus) { //?????? ???? ??????? ??? ??? ?????
? ? ? ? ? ? ? ?console.log(JSON.stringify(textStatus));
? ? ? ? ? }
});
??? ??????? ??????: