1

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);
        }
     });
}
6
  • 1
    You would use $('#divSettings').html(result);, so long as your ir_display_polls.php page returns the proper html. 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 Commented Oct 28, 2013 at 21:52
  • 1
    what is the result you receive? html? Commented Oct 28, 2013 at 21:52
  • result is not giving me latest update after delete the record..... Commented Oct 28, 2013 at 21:57
  • Then you have to return the latest update so it's in result. Commented Oct 28, 2013 at 21:59

3 Answers 3

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
        }
     });
}
Sign up to request clarification or add additional context in comments.

2 Comments

I tried that one.. But it's not reload the content.. After deleting record. it's still showing previous content until I am not refreshing the page manually.....
What does console.log($("#divSettings")); log? Whats the response of ../internal_request/ir_display_polls.php?
0

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

1 Comment

I tried that one.. But it's not reload the content.. After deleting record. it's still showing previous content until I am not refreshing the page manually.....
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.