Click here to Skip to main content
15,896,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
$(window).scroll(function () {
           if ($(window).scrollTop() == $(document).height() - $(window).height()) {
               GetRecords();
           }
       });
       function GetRecords() {
           pageIndex++;
           alert('PageIndex : ' + pageIndex + ' , Page Count : ' + pageCount);
           if (pageIndex == 2 || pageIndex <= pageCount) {


               $("#loader").show();
               $.ajax({
                   type: "POST",
                   url: "Default.aspx/GetCustomers",
                   data: '{pageIndex:'+pageIndex+'}',
                   contentType: "application/json; charset=utf-8",
                   dataType: "json",
                   success: OnSuccess,
                   failure: function (response) {
                       alert('Hell 1');
                   },
                   error: function (response) {
                       alert('Hell 2');
                   }
               });
           }
       }
       function OnSuccess(response) {
           var xmlDoc = $.parseXML(response.d);
           var xml = $(xmlDoc);
           pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
           var customers = xml.find("Customers");
           var repeatColumns = parseInt("<%=dlCustomers.RepeatColumns == 0 ? 1 : dlCustomers.RepeatColumns %>");
           var rowCount = Math.ceil(customers.length / repeatColumns);
           var i = 0;
           while (i < repeatColumns * rowCount) {
               var row = $("[id*=dlCustomers] tr").eq(0).clone(true);
               for (var j = 0; j < repeatColumns; j++) {
                   var customer = $(customers[i]);
                   if (customer.length == 0) {
                       //alert('Bingo');
                       $("table:last", row).remove();
                   } else {
                       $(".name", row).eq(j).html(customer.find("Name").text());
                       $(".productId", row).eq(j).html(customer.find("ProductId").text());
                       $(".description", row).eq(j).html(customer.find("Description").text());
                       $(".imageUrl", row).eq(j).html(customer.find("ImageUrl").text());
                       $(".image", row).eq(j).attr("src", 'Images/' + customer.find("ImageUrl").text());
                       $(".price", row).eq(j).html(customer.find("Price").text());
                       $(".quantity", row).eq(j).html(customer.find("Quantity").text());
                   }
                   i++;
               }
               $("[id*=dlCustomers]").append(row);
           }
           //$("[id*=dlCustomers] tr").eq(0).remove();
           $("[id*=dlCustomers]").show();
           $("#loader").hide();
       }
Posted
Comments
Sergey Alexandrovich Kryukov 13-Jun-15 2:51am    
What's wrong with just reading original jQuery documentation?
—SA

1 solution

Use the second signature of "scroll" function, the one with event data:
JavaScript
.scroll( [eventData ], handler )


And then pass any object you want to use inside the handler as event data; it will be passed as the handler argument:
JavaScript
var button = // say, you get the button wrapper
             // using some selector<pre lang="Javascript">
$(window).scroll(button, function (eventObject) {
   var passedButton = eventObject; // redundant line;
                                   // I wrote it only to
                                   // explain what's going on...
   //...
}


Read more carefully: https://api.jquery.com/scroll[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900