简体   繁体   English

使用Ajax jQuery刷新页面而不使用重新加载功能

[英]refresh page with ajax jquery without use of reload function

I am performing delete records by using jquery ajax in php. 我正在通过在PHP中使用jquery ajax执行删除记录。 I want to refresh that content without the use of location.reload() function. 我想在不使用location.reload()函数的情况下刷新该内容。 I tried this, 我试过了

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

but, it's not working. 但是,它不起作用。 What's the correct logic to get updated content in div. 在div中获取更新内容的正确逻辑是什么? Thanks. 谢谢。

Code: 码:

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

You're almost there: 你快到了:

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
        }
     });
}

You just needed to set the result into your '#divSettings' element using the .html() function : 您只需要使用.html()函数将结果设置为'#divSettings'元素:

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

So a full example would look like : 因此,完整的示例如下所示:

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);            
        }
     });
}

I believe you have to clear the section first and then you can attach the HTML again. 我相信您必须先清除该部分,然后才能再次附加HTML。 Like 喜欢

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);            
        }
     });
}

I believe this way you won't see the old content. 我相信这样您就不会看到旧内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM