ajax批删

 

<td><input type="checkbox"     name="bb"  value="{{$v->id}}"> {{$v->id}}</td>

 

<button id="pi">批删</button>

//批量刪除

$(document).on("click","#pi",function () {
nam=document.getElementsByName("bb");
str="";
for (i=0;i<nam.length;i++){
if (nam[i].checked==true){
str+=","+nam[i].value;

}
}
id=str.substr(1);
$.ajax({
url:"shan",
type:"post",
dataType:"json",
data:{
id:id
},
success:function (data) { console.log(data);
if (data==1){
location.href=""
}
}
})

})

 

function  shan(req $req){
$id= $req->post("id");
$id=explode(",",$id);

foreach ($id as $k=>$v){
$res= DB::table("poker")->delete($v);
}
return 1;
}

 

posted @ 2019-07-01 17:18  php毛宏历的博客  阅读(294)  评论(0编辑  收藏  举报