简体   繁体   中英

jQuery infinite scroll firing multiple ajax requests

I added some infinite scrolling from this tutorial and i've been stuck on ajax request. it's always requesting multiple times.

控制台img

and this is my code :

$(document).ready(function() {
  var win = $(window);
  var page = 1;
  var req = null;
  win.scroll(function() {
    if ($(document).height() - win.height() == win.scrollTop()) {
      if (req != null) {
        req.abort();
      }
      req = $.ajax({
        url: "/member/member_c/generate_data",
        type: "POST",
        data: {
          "page": page
        },
        dataType: "text",
        success: function(msg) {
          var obj = jQuery.parseJSON(msg);
          if (obj.result) {
            $('#contentz').append(obj.data);
            console.log(JSON.stringify('page ' + obj.page + ' : ' + jQuery.inArray(page,done)));                                
            page = page + 1;
            req = null;
          }
        },
      });
    }
  });
});

i've been wondering, what is 'VM' at my console and why is what always firing a 'wrong' request?

Thanks

It appears that you're including two copies of your code somehow, since one call comes from your member_c.js file and the copies come from VM22* sources. You should show us your entire source code for the page with this problem, not just this single snippet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM