跨域请求JSONP
作者:
猪丶八戒 | 来源:发表于
2017-08-30 10:51 被阅读0次function getJSONP(url, callback) {
var cbnum = "cb" + getJSONP.counter++
var cbname = "getJSONP." + cbnum
if(url.indexOf("?") === -1)
url += "?jsonp=" + cbname
else
url += "&jsonp=" + cbname
var script = document.creatElement("script")
getJSONP[cbnum] = function(res) {
try {
callback(res)
}
finally {
delete getJSONP[cbnum]
script.parentNode.removeChild(script)
}
}
script.src = url
document.body.appendChild(script)
}
getJSONP.counter = 0
本文标题:跨域请求JSONP
本文链接:https://www.haomeiwen.com/subject/vyuzdxtx.html
网友评论