jsonp 动态创建script
2021-07-01 12:05
标签:http 创建 动态创建 for loaded before data creat cti jsonp 动态创建script 标签:http 创建 动态创建 for loaded before data creat cti 原文地址:http://www.cnblogs.com/fqlGlog/p/7132669.htmlfunction loadScript(url, func) {
var head = document.head || document.getElementByTagName(‘head‘)[0];
var script = document.createElement(‘script‘);
script.src = url;
script.onload = script.onreadystatechange = function(){
if(!this.readyState || this.readyState==‘loaded‘ || this.readyState==‘complete‘){
func();
script.onload = script.onreadystatechange = null;
}
};
head.insertBefore(script, 0);
}
window.baidu = {
sug: function(data){
console.log(data);
}
}
loadScript(‘http://suggestion.baidu.com/su?wd=w‘,function(){console.log(‘loaded‘)});
//我们请求的内容在哪里?
//我们可以在chorme调试面板的source中看到script引入的内容
上一篇:web.config 开启缓存