【问题标题】:How can I refresh the contents of a DIV using JQuery? [duplicate]如何使用 JQuery 刷新 DIV 的内容? [复制]
【发布时间】:2014-11-24 18:26:51
【问题描述】:

我的用户有一个朋友列表,他们可以单击一个按钮将朋友从他们的朋友列表中删除。这是按照以下方式完成的。

一旦发生这种情况,我需要刷新#containerFriendsRequestSent,因为它的内容已经改变。我不能使用 location.reload(true);因为页面上有过滤器,这将重置它们,这意味着用户必须重新选择过滤器选项。

我以为我可以使用 $( "#containerFriendsRequestSent" ).load 之类的东西,但这似乎不会刷新页面?

 $('#containerFriendsRequestSent').append(wrapper);
   wrapper.children('.destroy').click(function() {
   $(".destroy").click(function() {
     item.fetchedObject.set("status", "Deleted");
     $('#containerFriendsRequestSent').load();

     item.fetchedObject.destroy(null, {
       success: function(results) {
       console.log("DELETED");
     },

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    您的 .load() 方法未正确使用。您必须提供一个参数来指定必须加载哪些数据。在您的情况下,您想重新加载页面的特殊容器,因此您必须这样做:

    $( "#containerFriendsRequestSent" ).load("YOUR-SITE.html #containerFriendsRequestSent" );
    

    看看jquery api:http://api.jquery.com/load/

    【讨论】:

    • 非常棒,非常适合我
    【解决方案2】:

    使用$('#containerFriendsRequestSent').html('');containerFriendsRequestSent 设置为空白,然后重新加载。

    【讨论】:

      【解决方案3】:

      如果删除项目服务器端的逻辑是有效的,为什么不使用“.remove()”删除节点呢?它会更快,如果他们重新加载页面,它将正确获取新朋友列表。

      【讨论】:

      • 我确实尝试了 .remove() 它没有问题地删除它,但之后没有正确更新 div
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      相关资源
      最近更新 更多