ajax获取数据

    xiaoxiao2021-03-25  152

    $(function(){  //链接地址  var url=window.basePath + 'jsonParam={"opeType":"getIndex"}';       $.ajax({     url:url,   //发送请求的url     type:"POST",   //http链接方式     dataType:"json",   //返回 JSON 数据     success:function(data){       //console.log(data);     输出信息 用于调试     if(data.return_code !="0"){ //返回值不是0     mui.alert(data.message,'提示');     }else{     var spccList= data.secondItemWindow;   //定义列表个数名称     for(var spc =0;spc<spccList.length;spc++){   //判断进行循环     $("#zlistli").append(   //在id为zlistli中插入内容     '<li class="spcc'+spc+'">'+   //添加插入内容     '<a href="javascript:void(0)" class="pl-pic" οnclick="productInfo(\''+spccList[spc].uuid+'\')"><div class="m_pic"><img src=""></div>'+     '<div class="m_tit"><h3></h3></div>'+     '</a></li>'         )     $('.spcc'+spc).find('a').find('img').attr('src',spccList[spc].imageUrl);   //在class名为spcc?的块中找到a标签下的img图像。attr获取选中元素的属性值src,获取图像     $('.spcc'+spc).find('h3').html(spccList[spc].name);   //在class名为spcc?的块中找到H3,并输出名称         }     var store = data.recommendedStore;                 if (store.length > 0) {                       for (var sto = 0; sto < store.length; sto++) {                         $("#five").append(                             '<li class="swiper-slide"><a οnclick="instore(\'' + store[sto].storeUuid + '\')">' +                             '<div class="m_pic"><img src="' + store[sto].logoPath + '"> </div>' +                             '<p class="y_name">' + store[sto].storeName + '</p>' +                             '</a></li>'                         )                     }

                    }

        }   //else里面内容加载结束

        //图片滑动 else加载完成后执行滑动效果 var swiper = new Swiper('.swiper-container', {     slidesPerView:2.5,     paginationClickable: true,     spaceBetween:10,      freeMode: false });         }  })

    })

    ajax调取多个块的数据,可以直接在else里面添加 

    先定义(var),判断对象是否有值,有值进行循环 获取 

    转载请注明原文地址: https://ju.6miu.com/read-12492.html

    最新回复(0)