zoukankan      html  css  js  c++  java
  • 跨域获取json电商数据

    url:http://www.darlingbank.com/cutpage/index.php/promote/edit/getfun/json/

    源碼:

    <ul class="cf" dataurl="http://www.paipai.com/sinclude/xml/tjw/tjw2014/tjw4/tjw179255804475.js" commlen="4" commsta="1" commtpl='<li><a href="{#recmdReason#}" target="_blank">{#recmdRegName#}</a></li>'>
    

    js:

    var J_data = {
        debug : true,
        log : function(s){
            this.debug && (window.console ? console.log(s) : alert(s));
        },
        create_script : function(src){
          var Scrip=document.createElement('script');
          Scrip.charset="gbk";
          Scrip.src=src;
          document.body.appendChild(Scrip);
        },
        get : function(){
          var thats=this;
          $("[dataurl]").each(function () {
            var that=this;
                dataurl=$(this).attr("dataurl"),
                tpl_tmp=$(this).attr("commtpl");
            if(typeof tpl_tmp==='undefined' || tpl_tmp===''){
              thats.log('请填写模板');
            }else{
              var c_str=dataurl.slice(dataurl.lastIndexOf('/')+1).split('.')[0];
    
              window[c_str]=function(j){
                var d=j.data.adList,html='',
                    len=parseInt($(that).attr("commlen")) || d.length,
                    start=parseInt($(that).attr("commsta")) || 0,
                    tpl=$(that).attr("commtpl");
                if(start>0 && len<d.length){
                  len +=start;
                }
                for(var i=start;i<len;i++){
                  html += tpl.replace(/{#recmdReason#}/g,d[i].recmdReason).replace(/{#recmdRegName#}/g,d[i].recmdRegName).replace(/{#image#}/g,d[i].image).replace(/{#adSentence#}/g,d[i].adSentence);
                }
                $(that).html(html);
              }
              // $.getScript(dataurl+"?callback="+c_str);  //亦可以用jquery方法
              thats.create_script(dataurl+"?callback="+c_str);
            }
          });
        }
      }
    $(function(){
      J_data.get();
    })
    

      

     

  • 相关阅读:
    4.28综合练习
    团队项目第一阶段冲刺第六天
    4.27防盗链和代理
    梦断代码阅读笔记3
    团队项目第一阶段冲刺第五天
    4.26抓取猪⼋戒数据
    团队项目第一阶段冲刺第四天
    4.25xpath解析
    4.24aiohttp模块学习
    如何将类数组转化为数组?
  • 原文地址:https://www.cnblogs.com/dennysong/p/3696803.html
Copyright © 2011-2022 走看看