Javascript 附加在延迟加载中无法正常工作

Javascript 附加在延迟加载中无法正常工作,javascript,jquery,append,lazy-loading,Javascript,Jquery,Append,Lazy Loading,我正在与我的代码斗争。我有一个asp.net页面,如下所示 <div id="div_goruntule" style="width:1217px;overflow:auto;height:200px;"> <asp:GridView ID="gw1" CssClass="gridview1" runat="server" AutoGenerateColumns="false" RowStyle-BackColor="#A1DCF2"

我正在与我的代码斗争。我有一个asp.net页面,如下所示

<div id="div_goruntule" style="width:1217px;overflow:auto;height:200px;">
            <asp:GridView ID="gw1" CssClass="gridview1" runat="server" AutoGenerateColumns="false" RowStyle-BackColor="#A1DCF2"
                HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White">
                <Columns>       
                    <asp:BoundField ItemStyle-Width="150px" ItemStyle-CssClass="datas" />
                    <asp:BoundField ItemStyle-Width="150px" ItemStyle-CssClass="idcolumn" DataField="Id" HeaderText="Id" />
                    <asp:BoundField ItemStyle-Width="150px" ItemStyle-CssClass="namecolumn" DataField="Name" HeaderText="Name" />
                    <asp:BoundField ItemStyle-Width="150px" ItemStyle-CssClass="surnamecolumn" DataField="Surname" HeaderText="Surname" />
                    <asp:BoundField ItemStyle-Width="150px" ItemStyle-CssClass="sexcolumn" DataField="Sex" HeaderText="Sex" />
                    <asp:BoundField ItemStyle-Width="150px" ItemStyle-CssClass="emailcolumn" DataField="Email" HeaderText="Email" />
                    <asp:BoundField ItemStyle-Width="150px" ItemStyle-CssClass="citycolumn" DataField="City" HeaderText="City" />
                    <asp:BoundField ItemStyle-Width="150px" ItemStyle-CssClass="agecolumn" DataField="Age" HeaderText="Age" />
                </Columns>
            </asp:GridView>
        </div>

"
+ ""
+“”+result.d[i].Id+“”+result.d[i].Name
+“”+result.d[i]。姓氏+“”+result.d[i]。性别
+“”+result.d[i]。电子邮件+“”+result.d[i]。城市
+“+result.d[i].Age+”;
}
},
错误:函数(xhr、状态、错误){
var err=eval(“+xhr.responseText+”);
警报(错误消息);
}
});
滚动时:

$("#div_goruntule").bind("scroll", function (e) {
    var $o = $(e.currentTarget);
    if ($o[0].scrollHeight - $o.scrollTop() <= $o.outerHeight()) {
        printValues();
    }
});
$(“#div_goruntule”).bind(“滚动”,函数(e){
var$o=$(e.currentTarget);

如果($o[0].scrollHeight-$o.scrollTop(),为什么要调用
$(“#gw1”).find(“td”).remove();
?哇!如果我不使用那一行,在数据之前会出现一个null tr元素。但是当我删除那一行惰性加载工作时,我解决了它。我只在第一个ajax post中使用了那一行,并从第二个post方法中删除了那一行
$("#div_goruntule").bind("scroll", function (e) {
    var $o = $(e.currentTarget);
    if ($o[0].scrollHeight - $o.scrollTop() <= $o.outerHeight()) {
        printValues();
    }
});
function printValues() {

    pageIndex++;

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "ShowRecord.aspx/GetRecords",
        data: '{pageIndex:' + pageIndex + '}',
        dataType: "json",
        success: function (result) {
            $("#gw1").find("td").remove();
            for (var i = 0; i < result.d.length; i++) {

                $("#gw1").append("<tr>"
                    + "<td id='options' style='width:150px;'>"
                    + "<a href='#' id='edit" + (i + 1) + "' style='padding:0px 20px;'>Edit</a>"
                    + "<a href='#' id='delete" + (i + 1) + "' style='padding:0px 20px;'>Delete</a></td>"
                    + "<td style='width:150px;'>" + result.d[i].Id + "</td><td class='name' style='width:150px;'>" + result.d[i].Name
                    + "</td><td style='width:150px;'>" + result.d[i].Surname + "</td><td class='sex' style='width:150px;'>" + result.d[i].Sex
                    + "</td><td style='width:150px;'>" + result.d[i].Email + "</td><td class='city' style='width:150px;'>" + result.d[i].City
                    + "</td><td style='width:150px;'>" + result.d[i].Age + "</td></tr>");
            }

        },
        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            alert(err.Message);
        }

    });
}
[System.Web.Services.WebMethod]
    public static ogrenci[] fnc(int pageIndex,int pageSize)
    {
        string text = "Data Source=YP202; Initial Catalog=Ogrenci; Integrated Security=true";

        DataTable dt = new DataTable();
        List<ogrenci> ogrList = new List<ogrenci>();
        using (SqlConnection con = new SqlConnection(text))
        {
            //string commandtext = "exec records5 @SayfadakiKayitSayisi,@SayfaNo";
            //using (SqlCommand command = new SqlCommand("select Id,Name,Surname,Sex,Email,City,Age from dbo.Student", con))
            using(SqlCommand command=new SqlCommand("[records5]"))
            {
                command.Connection = con;
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@SayfadakiKayitSayisi",10);
                command.Parameters.AddWithValue("@SayfaNo",pageIndex);
                SqlDataAdapter da = new SqlDataAdapter(command);
                da.Fill(dt);

                foreach (DataRow dtrow in dt.Rows)
                {
                    ogrenci ogr = new ogrenci();
                    ogr.Id = (int)dtrow["Id"];
                    ogr.Name = dtrow["Name"].ToString();
                    ogr.Surname = dtrow["Surname"].ToString();
                    ogr.Sex = dtrow["Sex"].ToString();
                    ogr.Email = dtrow["Email"].ToString();
                    ogr.City = dtrow["City"].ToString();
                    ogr.Age = (int)dtrow["Age"];
                    ogrList.Add(ogr);
                }

            }
        }
        return ogrList.ToArray();
    }