在ASPX页面上实现无限滚动时出现AJAX错误 [英] AJAX error in implementing infinite scroll on an ASPX page

查看:80
本文介绍了在ASPX页面上实现无限滚动时出现AJAX错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是ajax的新手,我正试图在aspx页面上实现无限滚动。但不幸的是,它显示了错误警报作为编码的ajax。请帮助我。

(SqlServer 2008,C#)

提前致谢,

Hritik



ASPX代码(C#)

Hi guys,
I am new to ajax, and I am trying to implement infinite scroll on an aspx page. But unfortunately its showing the "error" alert as coded ajax. Kindly help me out.
(SqlServer 2008, C#)
Thanks in advance,
Hritik

ASPX CODE (C#)

protected void Page_Load(object sender, EventArgs e)
  {
      if (!IsPostBack)
      {
          rptCustomers.DataSource = GetCustomersData(10);
          rptCustomers.DataBind();
      }
  }
  public static DataSet GetCustomersData(int pageIndex)
  {
      string query = "select top " + pageIndex + " * from DimCustomer";
      SqlCommand cmd = new SqlCommand(query);
      return GetData(cmd);
  }

  private static DataSet GetData(SqlCommand cmd)
  {
      string strConnString = "Data Source=.;Initial Catalog=adventure_works;Integrated Security=true;";
      using (SqlConnection con = new SqlConnection(strConnString))
      {
          using (SqlDataAdapter sda = new SqlDataAdapter())
          {
              cmd.Connection = con;
              sda.SelectCommand = cmd;
              using (DataSet ds = new DataSet())
              {
                  sda.Fill(ds, "DimCustomer");
                  return ds;
              }
          }
      }
  }
  [WebMethod]
  public static string GetCustomers(int pageIndex)
  {
    return GetCustomersData(pageIndex).GetXml();
  }









JAVASCRIPT( AJAX)代码







JAVASCRIPT (AJAX) CODE

<script src="scripts/jquery.js"></script>
    <script type="text/javascript">
     var pageIndex = 10;
    var pageCount;
    
    $(window).scroll(function () {
        if ($(window).scrollTop() == $(document).height() - $(window).height()) {
    GetRecords();      
        }
    }); 
    function GetRecords() {
        pageIndex=pageIndex+10;
        if (pageIndex == 20 || pageIndex <= pageCount) {
            $("#loader").show();
            $.ajax({
                type: "POST",
                url: "Default.aspx/GetCustomers",
                data: '{pageIndex= ' + pageIndex + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "xml",
                success: OnSuccess(response),
                failure: function (response) {
                    alert('failure');
                },
                error: function (response) {
                    alert('error');
                }
            });
        }
    }
    function OnSuccess(response) {
        var xmlDoc = $.parseXML(response.d);
        var xml = $(xmlDoc);
        var customers = xml.find("DimCustomer");
        customers.each(function () {
            var customer = $(this);
            var table = $("#dvCustomers table").eq(0).clone(true);
            $(".Fname", table).html(customer.find("FirstName").text());
            $(".Lname", table).html(customer.find("LastName").text());
            $("#dvCustomers").append(table).append("<br />");
        });
        $("#loader").hide();
    }
    </script>

推荐答案

window )。scroll( function (){
if
(window).scroll(function () { if (


window )。scrollTop()==
(window).scrollTop() ==


文件)。height() -
(document).height() -


这篇关于在ASPX页面上实现无限滚动时出现AJAX错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆