首页 > 滑动加载商品列表

滑动加载商品列表

商品列表htmL

所绑定的js事件

后台代码

$(function () {

//滚动加载

var stop = true;

var start = 2;

// $.ajaxSetup({async:false});

function getData(url){

// console.log(url);

$.ajax({

type:"get",//跨域访问时只能用get

url:url,//要访问的api地址

dataType:"json",

success:function(data){

// console.log(data);

var d = data;

// var d = data.subjects;

console.log(d);

var html = '';

for(i in d){

html += '

  • '

    +''

    +'
    '

    +'
    '+d[i].goods_name+':'+d[i].goods_content+'
    '

    +'
    '

    +'
    {$vol.goods_price}
    '

    +'
    点击兑换
    '

    +'
    '

    +'
    '

    +'
  • '

    start++;

    }

    console.log(html)

    stop = true;

    $('.ul').append(html);

    },

    });

    }

    $(window).scroll(function(){

    var url = "__CONTROLLER__/goodList?start="+start;

    var totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());

    // console.log(totalheight);

    if($(document).height() <= totalheight +120){

    if(stop == true){

    // console.log(totalheight);

    stop = false;

    // $('#j_loadmore').addClass('enabled');

    getData(url);

    }

    }

    })

    })

     

    转载于:https://www.cnblogs.com/caeserzxz/p/8677815.html