author:咔咔
wechat:fangkangfk
总结:其实就是点击删除的时候,直接将父级移除就可以了
//js代码 $('.coupondelete').click(function(){ var that = $(this); if(confirm('您确定要删除')) { var data = {'id':that.data('id')} $.ajax({ url:"{:U('/addon/WeiuidDeit/web/foodcouponDelect')}", type:'POST', data:data, dataType:'json', success:function(data){ data = JSON.parse(data); if(data.error == 200){ //直接移除父级的标签 that.parents('tr').remove(); } alert(data.msg); }, error:function(){alert('删除出错')} }) } })
后台控制器
// 优惠卷删除 public function foodcouponDelect() { $id = $_POST['id']; if (M('foodcoupon')->delete($id)) { $code['msg'] = '删除成功'; $code['error'] = '200'; } else { $code['msg'] = '删除失败'; $code['error'] = '400'; } $this->ajaxReturn(json_encode($code)); }