借助script发送http请求:jsonp
2016-03-21 17:57
489 查看
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.createElement('script'); getJSONP[cbnum] = function(response){ try{ callback(response); } finally{ delete getJSONP[cbnum];//删除该函数 script.parentNode.removeChild(script);//移除script元素 } }; //立即出发http请求 script.src = url;//设置脚本url document.body.appendChild(script); } //当页面全部加载以后 window.onload = function(){ getJSONP.counter = 0; getJSONP('http://api.taobao.com/apitools/ajax_props.do',function(res){ alert(res); }); };
相关文章推荐
- 听大神说:https和http有何区别?(转)
- http和socket之长连接和短连接区别
- muduo网络库脉络分析(2)
- 三大WEB服务器对比分析(apache ,lighttpd,nginx)
- 三种经典iPhone上网络抓包方法详解
- OkHttp和Okio
- OkHttp和Okio
- swift网络工具类
- tcprstat源码分析之tcp数据包分析
- iOS9 HTTP 通信报错解决方案
- java 网络流 TCP/UDP
- https工作原理
- TCP非阻塞通信
- 完美配置Tomcat的HTTPS
- 详解HTTPS:SSL证书申请、站点搭建等
- 更新了OS X EI Capitan 出现了source http://ruby.taobao.org/ already present in the cache
- 网络数据通信加密系统中加密解密流程
- 哪些网站需要HTTPS(SSL证书),至关重要吗?
- Android--广播的使用实例(监听网络连接)
- 网络程序的出错检测步骤