php ajax confirm Delete Instance Details

  • 2021-11-29 06:32:26
  • OfStack

This article mainly introduces the deletion example of php ajax confirm, and shares it with you and leaves a note for yourself, as follows:


<button name="del" type="button" class="btn btn-primary btn-xs" id="del"> Delete </button>

$("button[name=del]").click(function(){
 var statu = confirm(" Are you sure you want to delete ?");
 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( ' Delete succeeded ' );
 location.reload();
 }else{
 alert( ' Delete failed , Please try again later ' );
 }
 },
 error:function(){
 alert( ' Delete failed , Please try again later ' );
 }
 });
 });

 public function del()
 {
 $id=input('post.idd');
 $res = $this->section->del($id);
 echo json_encode($res);
 }

 /**
 *  Delete 
 */
 public function del($id)
 {
 $res = Section::destroy(['id' => $id]);
 return $res;
 }

Related articles: