【问题标题】:refresh page with ajax jquery without use of reload function使用 ajax jquery 刷新页面而不使用重新加载功能
【发布时间】:2013-10-28 21:49:52
【问题描述】:

我在 php 中使用 jquery ajax 执行删除记录。我想在不使用 location.reload() 函数的情况下刷新该内容。我试过了,

$("#divSettings").html(this);

但是,它不起作用。在 div 中获取更新内容的正确逻辑是什么? 谢谢。

代码:

function deletePoll(postId){
    $.ajax({
        type: "POST",
        url: "../internal_request/ir_display_polls.php",
        data: {
          postId: postId
        },
        success: function(result) {
            location.reload();
            //$("#divSettings").html(this);
        }
     });
}

【问题讨论】:

  • 您可以使用$('#divSettings').html(result);,只要您的ir_display_polls.php 页面返回正确的html。
  • 你使用的是this,而你应该使用result。需要用结果更新 Html
  • 您收到的result 是什么? html?
  • 删除记录后结果没有给我最新的更新.....
  • 那么你必须返回最新的更新,所以它在result

标签: javascript php jquery html ajax


【解决方案1】:

你快到了:

function deletePoll(postId){
    $.ajax({
        type: "POST",
        url: "../internal_request/ir_display_polls.php",
        data: {
          postId: postId
        },
        success: function(result) {
            $("#divSettings").html(result); // <-- result must be your html returned from ajax response
        }
     });
}

【讨论】:

  • 我试过那个..但它没有重新加载内容..删除记录后。它仍然显示以前的内容,直到我不手动刷新页面.....
  • console.log($("#divSettings")); 记录什么? ../internal_request/ir_display_polls.php的回复是什么?
【解决方案2】:

您只需使用 .html() 函数将结果设置到您的“#divSettings”元素中:

 $('#divSettings').html(result);

所以一个完整的例子看起来像:

function deletePoll(postId){
    $.ajax({
        type: "POST",
        url: "../internal_request/ir_display_polls.php",
        data: {
          postId: postId
        },
        success: function(result) {
            //Sets your content into your div
            $('#divSettings').html(result);            
        }
     });
}

【讨论】:

  • 我试过那个..但它没有重新加载内容..删除记录后。它仍然显示以前的内容,直到我不手动刷新页面.....
【解决方案3】:

我相信您必须先清除该部分,然后才能再次附加 HTML。喜欢

function deletePoll(postId){
    $.ajax({
        type: "POST",
        url: "../internal_request/ir_display_polls.php",
        data: {
          postId: postId
        },
        success: function(result) {
            //Sets your content into your div
            $('#divSettings').html("");
            $('#divSettings').html(result);            
        }
     });
}

我相信这样你就不会看到旧的内容了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 2014-09-06
    • 2021-05-15
    • 2019-11-20
    • 2017-12-24
    • 2012-12-15
    • 1970-01-01
    相关资源
    最近更新 更多