php ajax confirm 删除
<button name="del" type="button" class="btn btn-primary btn-xs" id="del">删除</button>
$("button[name=del]").click(function(){ var statu = confirm("确定删除吗?"); if(!statu){ return false; } var operation = {$res.id}; $.ajax({ type:'POST', url:"{:url('Sections/del')}", data:{idd:operation}, success:function(msg){ if(msg == 1){ alert( '删除成功' ); location.reload(); }else{ alert( '删除失败,请稍后重试' ); } }, error:function(){ alert( '删除失败,请稍后重试' ); } }); });
public function del()
{
$id=input('post.idd');
$res = $this->section->del($id);
echo json_encode($res);
}
/** * 删除 */ public function del($id) { $res = Section::destroy(['id' => $id]); return $res; }