javascript - Infinite data scroll in Yii2 -


i want make infinite scroll list in yii2

so far have done this, below jquery code

$(document).ready(function(){ var postparams ={user_id:'1',start:0,end:15}; $('#notificationlist').ready( function () {     $.ajax({         'url':'../../../frontend/web/app/notificationlist',         'type':'post',         'data': postparams,         success: function(data)         {             var notificationlist = data.notificationlist;             var notificationcount = data.notification;             if(notificationcount !== 0){                 $.each(notificationlist, function (index, value) {                     mood = notificationlist[index].mood_message;                     output = '<li id='+index+' value='+notificationcount+'>'+index +'</li>'+                     'first label'+                     'second label'+                     'third label'+                         'forth label'+                         'fifth label'+                         'six label';                     $("#notificationlist").append(output).promise().done();                 });             }         }     });   }); });  $(window).scroll(function(){ if ($(window).scrolltop() == $(document).height() - $(window).height()){     var start = parseint($('#notificationlist').children().last().attr('id'));     getresult(start);     } });  function getresult(start) { var postparams ={user_id:'1',start:start,end:7}; $.ajax({     'url':'../../../frontend/web/app/notificationlist',     'type':'post',     'data': postparams,     beforesend: function(){         $('#loader-icon').show();     },     complete: function(){         $('#loader-icon').hide();     },     success: function(data){          var notificationlist = data.notificationlist;         var notificationcount = data.notification;         if(notificationcount !== 0){             $.each(notificationlist, function (index, value) {                 mood = notificationlist[index].mood_message;                 output = '<li id='+index+' value='+notificationcount+'>'+index +'</li>'+                     'first label'+                     'second label'+                     'third label'+                     'forth label'+                     'fifth label'+                     'six label';                 $("#notificationlist").append(output).promise().done();             });         }     },     error: function(){}    }); } 

now problem don't know how control start , end in action , in jquery.

how can starting data , ending data on scroll, initial page can pass start point , end point, how check whether it's last record on page , send start , end point action?

just remember loaded items , use "new" start.

var alreadyloadeditems = 0; $('#notificationlist').ready( function () {     $.ajax({         'url':'../../../frontend/web/app/notificationlist',         'type':'post',         'data': {user_id:'1',start:alreadyloadeditems},         success: function(data)         {             var notificationlist = data.notificationlist;             alreadyloadeditems += data.notificationcount; // maybe 15 oder else             ... 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -