例如:
1.
在 jQuery 中,可以通過使用JSONP 形式的回調函數來加載其他網域的JSON數據,如 "myurl?callback=?"。jQuery 將自動替換 ? 為正確的函數名,以執行回調函數。
jQuery 會把?注冊成window.? 的系統函數,然后映射調用。
一般用於跨域ajax請求,提供URL的一方會返回一個callback函數的JSON數據,然后回調時就能獲取了。
請求的URL例子:
"myurl?callback=123123123" //這個123123就是?號,jquery自動生成的。
返回的數據例子:
123123123({“id”:"1","name":"張三"})
2.
var url="http://localhost:8080/WorkGroupManagment/open/getGroupById"
+"?id=1&callback=?";
$.jsonp({
"url": url,
"success": function(data) {
$("#current-group").text("當前工作組:"+data.result.name);
},
"error": function(d,msg) {
alert("Could not find user "+msg);
}
});
更多詳情請查詢 https://github.com/rccoder/blog/issues/5