Load more Content on Page Scroll with jQuery AJAX json

Last Reply 14 days ago By pandeyism

Posted 14 days ago

hi i want to load more data on scroll on reaching bottom of page..reply plzz

$(document).ready(function () {
    
    getdata();
     
});
function getdata() {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/WebService.asmx/Getdata",
        data: {},
        dataType: "json",
        success: function (data) {
          //  $('#dataTables-example tbody').remove();
            //console.log(data.d);
            var table = $('#dataTables-example');
            var rows = "";
            for (var i = 0; i < data.d.length; i++) {
                var ID = data.d[i].ID;
                var Name = data.d[i].Name;
                     var image = '<img class=imgstore width=100px height=100px, src="data:image/jpg;base64,' + data.d[i].image + '" />'
                     rows += "<tr><td>" + ID + "</td><td>" + Name + "</td><td>" + image + "</td>";
                     }
            table.append(rows);
        },
        error: function () {
            alert("Error while Showing update data");
        }
    });
}

 

[WebMethod]
public List<Customer> GetData()
{
    List<Customer> customers = new List<Customer>();
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    string query = "SELECT CustomerId,Name,Country FROM Customers";
    SqlCommand cmd = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
    {
        cmd.Connection = con;
        con.Open();
        SqlDataReader sdr = cmd.ExecuteReader();
        while (sdr.Read())
        {
            customers.Add(new Customer
            {
                Id = Convert.ToInt32(sdr["CustomerId"]),
                Name = sdr["Name"].ToString(),
                Country = sdr["Country"].ToString()
            });
        }
        con.Close();
    }
  
    return customers;
}

 

You are viewing reply posted by: pandeyism 14 days ago.