我不能將ID發送給PHP刪除的行,我得到這個錯誤廣東話刪除或發送數據到PHP
TypeError: 'checkValidity' called on an object that does not implement interface HTMLButtonElement.
如果我這樣做腳本
jQuery(document).on("click",".del_beneficiaries",function(){
var id = jQuery(this);
jQuery.ajax({
type: "POST",
dataType: "json",
url: "ben_del.php",
data: {
"id" : id
}
});
});
,但如果這樣做這腳本他們是沒有數據發送到我的PHP
jQuery(document).on("click",".del_beneficiaries",function(){
var id = [];
jQuery(".beneficiaries_rows").each(function(){
var rows = jQuery(this).attr("data-id");
id.push(rows);
});
jQuery.ajax({
type: "POST",
dataType: "json",
url: "ben_del.php",
data: {
"id" : id
}
});
});
另外,如果我讓這個腳本仍然沒有數據發送到PHP
jQuery(document).on("click",".del_beneficiaries",function(){
var id = [];
jQuery(".data-id").each(function(){
var rows = jQuery(this).closest(".beneficiaries_rows");
id.push(rows);
});
jQuery.ajax({
type: "POST",
dataType: "json",
url: "ben_del.php",
data: {
"id" : id
}
});
});
這是HTML
<table style="border: 2px solid black;margin:auto;">
<tr>
<th width="100%"><center>Name<center></th>
<th><center>Action</center></th>
</tr>
<?php
while($row1 = mysql_fetch_array($result1)){
echo "<tr class='beneficiaries_rows' id='".$row1['id']."' value='".$row1['ben_id']."'>";
echo "<td>".$row1['name']."</td>";
echo "<td>";
echo "<center><button class='del_beneficiaries'>X</button><center>";
echo "</td>";
echo "</tr>";
}
?>
</table>
你正在推動的jQuery對象轉換成數組發送數據。當jQuery嘗試序列化它們時會中斷。你想要發送什麼?你有選擇器不匹配HTML – charlietfl
@charlietfl即時通訊發送ben_id到我的PHP刪除它的名稱 – reyjoel