我想點擊刪除按鈕,我正在使用AJAX後刪除行的記錄,我嘗試以下,但它給我一個錯誤:刪除記錄在AJAX
//index.php
$(document).on('click', '.delete', function(){
var Serial = $(this).attr("Serial");
if(confirm("Are you sure you want to remove this data?"))
{
var action = "Delete";
$.ajax({
url:"plans-action.php?square=$selsquare",
method:"POST",
data:{Serial:Serial, action:action},
success:function(data)
{
fetchUser();
alert(data);
}
})
}
else
{
return false;
}
});
});
//plans-fetch.php
這裏是我的在服務器端PHP代碼
if(isset($_POST["action"]))
{
if($_POST["action"] == "Delete")
{
$statement = $connection->prepare(
"DELETE FROM plans WHERE SquareNo = '$selsquare' AND Serial = :Serial"
);
$result = $statement->execute(
array(
':Serial' => $_POST["Serial"]
)
);
if(!empty($result))
{
echo 'Data Deleted';
}
}
}
像
data-serial="somevalue"
,而不是Serial="somevalue"
然後你能告訴我們你的錯誤? –
你會得到什麼錯誤? –
您還需要從$ _GET獲取$ selsquare以傳遞查詢 –