[英]How Data Delete row from database with AJAX
這是我的PHP代碼
AjaxServer.php
include '../include/connection.php';
//here check the prediction
if(isset($_POST["delete_me"]) && $_POST["delete_me"]=="true"){
$id = $_POST["id"];
$table = $_POST["table"];
$query = "delete from {$table} where id='{".$id."}'";
if(mysql_query($query)){
echo "record has been deleted";
}
}
這是我的js文件Custom.js
$(document).ready(function() {
$('a.delete').click(function(e) {
if(confirm("Do you realy want to delete this")){
e.preventDefault();
var parent = $(this).parents("tr");
var table = $(this).attr("data-table");
var id = $(this).attr("id");
var data ="id="+id+"&delete_me=true&table="+table;
$.ajax({
type: 'post',
url:'include/ajaxserver.php',
data: data,
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function() {
parent.slideUp(500,function() {parent.remove();});
}
});
}
else{
return false;
}
});/*end of the cick function*/
});/*end of the ready function*/
您沒有將數據發送到ajax文件中,請按照以下說明正確替換ajax代碼:
$.ajax({
type: 'post',
url:'include/ajaxserver.php',
data: {id: id, delete_me: true, table :table},
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function() {
parent.slideUp(500,function() {parent.remove();});
}
});
希望這段代碼對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.