首页 > Web开发 > 详细

jsonp的函数实现

时间:2014-09-24 15:24:38      阅读:295      评论:0      收藏:0      [点我收藏+]

 

自己写的jsonp函数封装

 

getJsonp:function(url,fn){
       var callback=‘c_brand_jsonp‘+String(Math.random()).replace(‘.‘,‘‘);
       url=url+‘&callback=‘+callback;
       var script=document.createElement(‘script‘);
      script.id=‘c_brand_script‘;
      script.type="text/javascript";
      script.src=url;
      document.getElementsByTagName(‘head‘)[0].appendChild(script);
      window[callback]=function(json){
           document.getElementsByTagName(‘head‘)[0].removeChild(document.getElementById(‘c_brand_script‘));
           fn(json);
      }
 }

jsonp的函数实现

原文:http://www.cnblogs.com/webcheng/p/3990642.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!