javascript - refresh page with ajax jquery without use of reload function - Stack Overflow

I am performing delete records by using jquery ajax in php. I want to refresh that content without the

I am performing delete records by using jquery ajax in php. I want to refresh that content without the use of location.reload() function. I tried this,

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

but, it's not working. What's the correct logic to get updated content in 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);
        }
     });
}

I am performing delete records by using jquery ajax in php. I want to refresh that content without the use of location.reload() function. I tried this,

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

but, it's not working. What's the correct logic to get updated content in 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);
        }
     });
}
Share Improve this question asked Oct 28, 2013 at 21:49 Ronak PatelRonak Patel 3901 gold badge3 silver badges12 bronze badges 6
  • 1 You would use $('#divSettings').html(result);, so long as your ir_display_polls.php page returns the proper html. – Jason P Commented Oct 28, 2013 at 21:52
  • You're using this when you should be using result. Html needs to be updated with the result – rogMaHall Commented Oct 28, 2013 at 21:52
  • 1 what is the result you receive? html? – Lachezar Commented Oct 28, 2013 at 21:52
  • result is not giving me latest update after delete the record..... – Ronak Patel Commented Oct 28, 2013 at 21:57
  • Then you have to return the latest update so it's in result. – kelunik Commented Oct 28, 2013 at 21:59
 |  Show 1 more ment

3 Answers 3

Reset to default 1

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 :

 $('#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. 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742284286a4415048.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信