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 yourir_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 usingresult
. 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
3 Answers
Reset to default 1You'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条)