1

我将在我的 ASP.NET Web 应用程序中实现 JQuery 无限滚动,我使用以下 jquery funcyion(取自http://code.msdn.microsoft.com/CSASPNETInfiniteLoading-16f5bdb8):

$(document).ready(function () {

       function lastPostFunc() {
           $('#divPostsLoader').html('<img src="images/bigLoader.gif">');

           //send a query to server side to present new content
           $.ajax({
               type: "POST",
               url: "Default.aspx/Foo",
               data: "{}",
               contentType: "application/json; charset=utf-8",
               dataType: "json",
               success: function (data) {

                   if (data != "") {
                       $('.divLoadData:last').after(data.d);
                   }
                   $('#divPostsLoader').empty();
               }

           })
       };

divLoadData 是一个将接收数据(HTML 格式)的 div,但我想将数据附加到 asp.net 表中,如何附加数据?我应该使用后功能?另外我应该如何生成我的 HTML 以附加到这个服务器端表格控件,当前数据是使用以下代码创建的(在 webmethod 函数中):

  foreach (DataRowView myDataRow in dv)
            {
                getPostsText.AppendFormat("<p>author: {0}</br>", myDataRow["author"]);
                getPostsText.AppendFormat("genre: {0}</br>", myDataRow["genre"]);
                getPostsText.AppendFormat("price: {0}</br>", myDataRow["price"]);
                getPostsText.AppendFormat("publish date: {0}</br>", myDataRow["publish_date"]);
                getPostsText.AppendFormat("description: {0}</br></p>", myDataRow["description"]);
            }
            getPostsText.AppendFormat("<div style='height:15px;'></div>");

最后getPostsText被发送到 JQuery

4

2 回答 2

1

您可以使用 jQuery 中的 .after() 函数在另一个元素之后附加一些内容。

所以而不是

$("servers").append( ... );

你会用

$("#" + id + ).closest( "tr" ).after( ... );

或者你也可以使用

$( ... ).insertAfter( $("#" + id ).closest( "tr" ) );

这本质上是等价的。

有关详细信息,请参阅http://api.jquery.com/after/

于 2013-03-25T07:21:43.247 回答
1

您必须将功能移出doc ready

function lastPostFunc() {
       $('#divPostsLoader').html('<img src="images/bigLoader.gif">');
       $.ajax({
           type: "POST",
           url: "Default.aspx/Foo",
           data: {},
           contentType: "application/json",
           dataType: "json",
           success: function (data) {
               if (data != "") {
                   $('#divDynamicData').append(data.d);
               }
               $('#divPostsLoader').empty();
           }
       });
   }


$(document).ready(function () {
  $(window).scroll(function(){
     if ($(window).scrollTop() == $(document).scrollHeight - $(window).height()) {
         lastPostFunc();
     }
  });
});   
于 2013-03-25T07:31:05.983 回答