jsonpによるドメイン間アクセス
1915 ワード
, , jsonp , jsonp , 。 。
jsonp , 。
callback, callback ( )。 , json 。
javascript , function , function jsonp. json , function , js , 。 , script , javascript , , callback .( )
JSONP , JS script , src URL。 , URL GET ( URL ), —— , JSON, ( ) , :callback({json_data})。 , callback(data) , , 。
script :
$(document).ready(function (){ // JSONP ,url
var script =document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src",“ url”);
script.setAttribute("id", url);
document.appendChild(script);});
===========Javascript :JSONP , =======================
function jsonpCallback(obj){
alert(obj.msg);
}
------------------END------------------------
=============== ==================
java.io.PrintWriter out = getResponse().getWriter();
out.println("jsonpCallback({msg:' ',name:' '})");
out.close();
。
:jsonpCallback({msg:' ',name:' '}) JavaScript , jsonpCallback , 。