tp5项目后台删除

控制器

public function bajax(){
        $id = input('id');
        $arr = [];
        $a = db('basgame')->where('id',$id)->select();
        if($a) {
            $arr['code'] = 1;
            db('basgame')->where('id',$id)->delete();
            db('basguess')->where('gid',$id)->delete();
        }
        return $arr;
        //通过Ajax,将传过来的比赛id在数据库中查询,如果有结果,则在比赛和竞猜数据库中都删除掉该记录,再返回数组来确定是否删除成功
    }

视图html

 <button class="del layui-btn layui-btn-danger" data-id="{$vo.id}">删除</button>
$('.del').click(function(){
        var id = $(this).data('id');
        var that = $(this);
        layer.confirm('确定删除'+id+'吗?',{icon: 3,title: '提示'},function(index){
          $.ajax({
            //ajax用法
            url:'{:url("index/bnajax")}',
            //与哪个文件进行传递
            type:'post',
            //传递方式
            data:{id:id},
            dataType:'json',
            //返回类型
            success:function(res){
              //执行函数
              console.log(res);
              layer.close(index);
              if (res.code==1){
                location.reload();
              }else{
                layer.msg('删除失败!');
              }
            }

          });
        });
      });
posted @ 2020-08-13 14:40  HighKK  阅读(168)  评论(0编辑  收藏  举报