在下面的代码中,我尝试使用ajax .serialize()删除一行,但它只删除第一行。使用jQuery(this).closest('form')。find('input [name =“id “]')VAL();也会为ID返回“未定义”。
Ajax代码
function AjaxDelete() {
var rowId = $("#sil").serialize();
var confirmation = confirm("Are you sure of deleting the following user:"+rowId);
if (confirmation) {
$.ajax({
type:'POST',
url:'sil.php', //deleting file
data: rowId,
success:function(cevap){
alert("User has been successfully removed.ID="+rowId);
}
});
}
return confirmation;
};
表格结构
echo '<table id="kullanicilar" align=center>
<thead>
<tr>
<td></td>
<td>ID</td>
<td>Kullanıcı Adı</td>
<td>Yönetici</td>
<td colspan=4>İşlemler</td>
</tr>
</thead>
';
while($results->fetch()){ //fetch values
echo '<tr>
<td><input type="checkbox" name="select[]" value="'.$id.'"></td>
<td>'.$id.'</td>
<td>'.$kullanici_adi.'</td>
<td>'.$yonetici.'</td>
<td><a href="#" onclick="return AjaxDelete();" class="link"><form method="post" id="sil"><input type="hidden" name="id" value="'.$id.'" class="id"></form><img src="img/delete.png" title="Sil"></a></td>
<td><a href="#"><img src="img/edit.png" title="Düzenle"></img></a></td>
<td><a href="#" class="gor">Gönderilerini Gör</a></td>
<td><a target="_blank" href="#" class="gor">Profilini Gör</a></td>
</tr>
'
;
}
echo '</table><br/>';
答案 0 :(得分:0)
在你的while循环中,你给错误的输入id
。你可以尝试:
<a href="#" onclick="return AjaxDelete("'.$id.'");" class="link"><form method="post" id="sil">
然后在你的ajax中:
function AjaxDelete(x) {
var rowId = x;