jsonp的函数实现

 

自己写的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);
      }
 }

posted @ 2014-09-24 14:29  二进制工作者  阅读(158)  评论(0编辑  收藏  举报