2013-03-25 52 views
1

我要实现我的ASP.NET web应用程序的JQuery无限滚动后使用数据添加到asp.net表,我用以下的jQuery funcyion(从http://code.msdn.microsoft.com/CSASPNETInfiniteLoading-16f5bdb8拍摄):jQuery函数

$(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的

回答

1

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

所以不是

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

你会使用

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

,或者您也可以使用

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

基本上是相等的。

请参阅http://api.jquery.com/after/了解详细信息。

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(); 
    } 
    }); 
}); 
+0

为什么要我将其移出doc_ready的? – 2013-03-25 07:35:34

+0

,因为你必须在scroll和functions中调用它或者应该在docready中初始化它,或者像在答案中那样调用它。 – Jai 2013-03-25 07:37:09

+0

我打算在示例中使用div,但没有将数据添加到我的div中,并且在某些时刻我只看到了我的gif图像,然后没有任何内容添加到我的页面,出了什么问题? – 2013-03-25 07:40:27