//先引进javascript
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
//html
<td><a href="javascript:;" class="del" ids="{{$val['id']}}">ajax删除</a></td>
//js
$('.del').click(function (){
//获取id的值
var id = $(this).attr('ids');
//定义指定的值,当前回事指a标签
var _this = $(this);
$.ajax({
//路由
url:'del',
//数据
data:{id:id},
//类型
type:'get',
//返回类型
dataType:'json',
success:function (res)
{
var code = (res.code);
if (code==200)
{
_this.parents('tr').remove();
}
}
})
})
//controll
/**
*ajax异步删除
*/
public function del()
{
$id = \request()->get('id');
//dd($id);
$message = modeller::where('id',$id)->delete();
if ($message)
{
return json_encode(['code'=>200,'msg'=>'成功','data'=>$message]);
}
}