什么是jsonp,jsonp是什么,jsonp如何使用 JSONP ??, JSONP ??, JSONP ?????? ??????? ????? JSONP ??, JSONP ??, JSONP ?????? ??????? ?????
?????????? ????????? ??????????? ?????, ???? ?????? ????-?????? (??????? ??? ??????, ???????? ?????? ??????, ???? ??????? ????? ???????????) ?????? ??? ???? ??, ?????? ?? ?????? ?????? ?????? ?????? ???? ?????? ????? ???? crossdomain.xml ??? ??? ???? http ?????? ??????? ???????
?????? crossdomain.xml ?????? ???? ?? ????????????? ????? ???? ????????? ???? ????, ??? ????? ??? ??? ??? ?????
????? ???? ????? ???????? ???? ???????? jsonp ??? ???? ????? ???? ??? ????????? ????? ???????? ???? ????????? ???? ?????
jsonp ?? ????????? ?????? ??????? ???? ???? ?????
?????????, ???? ??? ???? ?????????? js ??????????? ????, ????? ?? ??????? js ????? ?????????? ??? ?? ???? ?????
????????????? ?????? ??? js ??? ???????? ????????? ??? (jsp, php, aspx) ???? ?????? ??? ????????????? ????? ?????? ????
function showjson(json){
alert(json.url);
}
如果引用的js或動(dòng)態(tài)頁(yè)面里有 showjson({"url":" http://www.bjljyy.com "});這行代碼的話(huà),那就會(huì )彈出 http://www.bjljyy.com
???? ???? ?? ???????? ?????? ????? http://www.ibilibili.com/static/js/forbejson/userinfo.php ????? ????, ?? php ????? ???? ???? ??????? ????? showjson ??????? ????, ?? ?????? ?? bejson ????? showjson ???????? ?? ???? ??? ???? json ??????:
< ?php
//??? php ????????, showjson ???????? ?? ??? ?????, ?? ??????? ??? ?????? ???? ?????????? ???????? ???????? ??????? ??????? ???? ???? ???? ????
echo 'showjson({"url":"http://www.bjljyy.com"})';
?>
????? ????????? ???? ???????:
$("#getuserp").click(function(){
$.getScript("http://www.bjljyy.com/test/userinfop.php");
});
????? ??? ???? ??????? ???? ????, ????? ???? ????? ???? (????? ???? ???), ?????? ????? ???? ?? ???? HTTP ?????? ???? ??????,
?????? ??? ??????// www.bjljyy.com/test/userinfop.php ????,
頁(yè)面里輸出了 showjson({"url":" http://www.bjljyy.com "}) ,
???? ??? ?????? ????????????? ?????? ???? ??? ??? ??????? ????? ?? ???????? ???????? showjson ?? ??? ???? ??????? ???? ???? (???? ????? ?????), ??? json ??????????? ??? ???? (??? ????? ?????), ??? json ?? ????? url ?? ?? ?? ???? ?????
???????
???
????? ??? ??????? ???? ??? ???? ??? ?????? ?????
?x $.ajax({
? ? url:'//www.bjljyy.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));
? ? ? ? ? }
});
???? ?????????????? ??????? ??????: