php&mysql的数据删除 ajax
php中的删除 php代码
$('.del').click(function(){
var id = $(this).data('id');
var that = $(this);
layer.confirm('确定删除' + id + '吗?', {
icon: 3,
title: '提示'
},
function(index){
$.ajax({
url:"/json.php",
type: 'post',
data: {id:id},
dataType: 'json',
success: function(res) {
console.log(res);
layer.close(index);
if (res.code == 1) {
// that.parents('tr').remove();
location.reload();
} else {
layer.msg('删除失败!');
}
}
});
});
});
一个jq的函数就能实现
ajax代码
if($_POST){
$ids=$_POST['id'];
$conn=new mysqli('localhost','root','root','qiyewangzhan');
$sql="delete from product where id=$ids" ;
$res=$conn->query($sql);
$arr=[];
}
if($res){
$arr['code']=1;
}else{
$arr['code']=2;
}
echo json_encode($arr);
posted on 2020-06-12 09:23 vermouthmo 阅读(192) 评论(0) 收藏 举报
浙公网安备 33010602011771号