2
有更聰明的方法來刪除ajax請求的行?刪除行AJAX
這裏我使用的代碼,也許有更好更安全的方法。
BUTTON
<a href="#" msg_id="<? echo $msg_id; ?>" class="delete-btn"> DELETE </a>
AJAX
$('.delete-btn').click(function(){
// Confirm
///if (! confirm('Are you sure want to delete this row?')){
// return false;
// }
// id need to delete
var msg_id = $(this).attr('msg_id');
// Current button
var obj = this;
// Delete by ajax request
$.ajax({
type : "post",
dataType : "text",
url : 'messages_sql.inc.php?a=message_delete',
data : {
msg_id : msg_id
},
success : function(result){
$(obj).parent().parent().remove();
window.location.assign('messages.php?msg=deleted');
}
});
});
'messages_sql.inc.php'是做什麼用的?它是否檢查用戶的會話以確認他們有權刪除他們將刪除的記錄? – chris85
你不應該組成你自己的屬性。使用'data-msg_id'而不是'msg_id'。 – Barmar
messages_sql.inc.php只有SQL QUERY $ msg_id = $ _POST ['msg_id']; \t \t \t $ sql =「DELETE FROM db_messages WHERE msg_id = $ msg_id」; – user1504222