admin管理员组文章数量:1426015
I need to remove a table row after a successful ajax call, not sure how to do it. Here is my code:
function closelead(rowid){
var rowid1 = rowid;
alert(rowid1);
var parent = $(this).parent();
$.ajax({
type: "POST",
url: "ajax/close.php",
data: "rowid="+ rowid1,
success: function(html){
}
});
}
<tr><td><input type="button" onclick="closelead(<?php echo $leadlist['ID'];?>)" value="Close" class="searchbutton" /></td></tr>
I need to remove a table row after a successful ajax call, not sure how to do it. Here is my code:
function closelead(rowid){
var rowid1 = rowid;
alert(rowid1);
var parent = $(this).parent();
$.ajax({
type: "POST",
url: "ajax/close.php",
data: "rowid="+ rowid1,
success: function(html){
}
});
}
<tr><td><input type="button" onclick="closelead(<?php echo $leadlist['ID'];?>)" value="Close" class="searchbutton" /></td></tr>
Share
Improve this question
asked Dec 4, 2012 at 6:16
savagenoobsavagenoob
4139 silver badges26 bronze badges
3
-
your javascript and html looks solid (Sean's answer has a nice structure though). your problem may be something else entirely; on the success function, put a line to
alert(html);
. also add anerror: function(html) { alert(html); }
also. – rkw Commented Dec 4, 2012 at 8:02 - @rkw it returns the echo from the php "true". its pleting the mysql query on the back end but its not executing $(this).closest('tr').remove(); – savagenoob Commented Dec 5, 2012 at 2:55
-
append
return false;
to youronclick
statement; to prevent any postback that may occur. inside yoursuccess
function, use the code from Adil. If that doesn't work, instead of the code from Adil, put inconsole.log($(this).closest('tr'))
and see what object the console returns – rkw Commented Dec 5, 2012 at 6:31
5 Answers
Reset to default 2You can use closest() to find out the row containing the clicked button and use remove() to remove the row of button.
success: function(html){
$(this).closest('tr').remove();
}
Onclick is so 1999...
$('#closelead').on('click', function() {
var $row = $(this).parent().parent();
var rowid = $(this).data("row-id");
$.ajax({
type: "POST",
url: "ajax/close.php",
data: "rowid=" + rowid,
success: function() {
$row.remove();
}
});
});
Change HTML to this.
<tr><td><button id="closelead" class="searchbutton" data-row-id="<?php echo $leadlist['ID'];?>">Close</button></td></tr>
DEMO
Look in your code you already have var parent = $(this).parent();
declared.
Now after successful ajax response use parent.parent().remove();
This would be easy and understandable too.
use remove().
$(this).closest('tr').remove();
Have a look at Jquery remove - it will do the trick
本文标签: phpjQuery Remove table row on ajax successStack Overflow
版权声明:本文标题:php - jQuery Remove table row on $.ajax success - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745404242a2657177.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论