【发布时间】:2014-04-29 12:02:58
【问题描述】:
当我按下删除按钮时,它不会删除内容。 我认为ajax删除调用有问题
ajax-file.php
$('.delete_update').live("click",function() {
var ID = $(this).attr("id");
var dataString = 'msg_id='+ ID;
if(confirm("Sure you want to delete this update? There is NO undo!")) {
$.ajax({
type: "POST",
url: "delete_data.php",
data: dataString,
cache: false,
success: function(html){
$("div#bar"+ID).slideUp('slow', function() {$(this).remove();});
}
});
}
return false;
});
<div class="accordionButton" id="bar<?php echo $msg_id; ?>"><?php echo $msg_id; ?>:<?php echo $name; ?>
<a href="#" id="<?php echo $msg_id; ?>" class="delete_update">X</a>
</div>
<div class="accordionContent" style="display: block;"><?php echo $msg; ?></div>
delete_data.php
<?php
include("db.php");
if($_POST['msg_id'])
{
$id=$_POST['msg_id'];
$id = mysql_escape_String($id);
$sql = "delete from messages where msg_id='$id'";
mysql_query( $sql);
}
?>
【问题讨论】:
-
那么点击事件是否触发?控制台中的任何错误?更好地解释您的问题
-
用FF/Firebug/Chrome查看Post请求是否发送,判断是js还是php代码有问题。
-
您是否意识到任何人都可以从您的数据库中删除内容,因为您根本不验证任何输入?此外,当 HTTP 方法中有
DELETE方法可用时,您不应该使用POST删除内容。 -
它什么都不做。不运行ajax。所以我认为它一定是按钮的东西?
-
我认为数据传递不正确
data: { msg_id: dataString }