echo '<td><a class="delete" href="#" id="'.$row['Id'].'">Delete</a></td>';
<script type="text/javascript">
$(function() {
$(".delete").click(function(){
var element = $(this);
var del_id = element.attr("id");;
var info = 'id=' + del_id;
if(confirm("Are you sure you want to delete this?"))
{
$.ajax({
type: "POST",
url: "ajax_delete.php",
data: info,
success: function(){
}
});
$(this).parents("#checkboxlist").animate({ backgroundColor: "#003" }, "slow")
.animate({ opacity: "hide" }, "slow");
}
return false;
});
});
</script>
ajax_delete.php
<?php
session_start();
include "config.php";
$id=$_REQUEST['id'];
$record = mysql_query("delete from contact_form where Id = '$id'",$con);
if($record)
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=list.php">';
$_SESSION['deleted']="yes";
}
else
{
echo mysql_error();
}
?>
我还添加了 jquery 库。尝试了所有可能的事情。但是表格不会刷新。数据被删除。但是只有在我刷新页面时才会反射(reflect)出来。我对此感到沮丧。
最佳答案
你需要在页面中删除它,然后,在它成功删除之后。
success: function(){
element.remove();
}
关于php - 删除 PHP mysql 行时 Ajax 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34505468/