【发布时间】:2016-01-09 14:42:07
【问题描述】:
我想从我的 html 以及我的数据库中删除特定的行,单击该行中的相应按钮。到目前为止,我只能从我的 html 表中删除它,但我不知道如何从我的数据库中删除它。我知道它会涉及 ajax 代码,但我不太熟悉使用它,所以请帮忙
这是我的html-
<div id="divGrid">
<table class="footable" data-filter="#filter" id="tableresult">
<thead>
<th>Client name</th>
<th>Staff name</th>
<th>Matter</th>
<th> Delete</th>
</thead>
<tr id="<?php echo $id; ?>" class="edit_tr">
<td class="edit_td" >
<span id="client_<?php echo $id; ?>" class="text"><?php echo $clientname; ?></span>
<input type="text" value="<?php echo $clientname; ?>" class="editbox" id="client_input_<?php echo $id; ?>" />
</td>
<td class="edit_td">
<span id="staff_<?php echo $id; ?>" class="text"><?php echo $staff; ?></span>
<input type="text" value="<?php echo $staff; ?>" class="editbox" id="staff_input_<?php echo $id; ?>"/>
</td>
<td class="edit_td">
<span id="matter_<?php echo $id; ?>" class="text"><?php echo $matter; ?></span>
<input type="text" value="<?php echo $matter; ?>" class="editbox" id="matter_input_<?php echo $id; ?>"/>
</td>
<td class="delete_td"><input type="button" id="del" class="btn btn-danger" value="×"></input></td>
</tr>
and here is my jquery-
$(document).ready(function () {
$('input[type=button]').click(function () {
$(this).parent().parent().remove();
if ($('#tableresult tr').length < 2) {
$('#divGrid').empty();
$('#divGrid').html("All item removed");
}
});
});
这样我就可以在上面实现我的代码。我怎么做? 请检查一下这有什么问题-
$(document).ready(function () {
$('input[type=button]').click(function () {
var row = $(this).attr('id');
$.ajax({
type: "POST",
url: 'delete.php',
data: {id: row},
success: function (result) {
$(this).parent().parent().remove();
if ($('#tableresult tr').length < 2) {
$('#divGrid').empty();
$('#divGrid').html("All item removed");
}
}
});
});
});
php代码-
【问题讨论】:
-
你想做什么?您的专栏有类
delete_td。您可以将此作为列的参考。
标签: php jquery html mysql button