您的位置:首页 > 其它

AJAX.JQ一些基本用法

2018-03-19 11:39 483 查看
1.ajax  的运用 --------------------(1)点击按钮 
(2)js部分       function deleteuser(obj,id){        var token = "{{csrf_token()}}";        layer.confirm('确认要删除吗?',function(index){            $.ajax({                type: 'POST',                url: '/admin/qiye/del',                data:{id:id,_token:token},                dataType: 'json',                success: function(data){                    if(data.status == 200) {                        $(obj).parents("tr").remove();                        layer.msg('已删除!', {icon: 1, time: 1000});                    } else {                        layer.msg('删除失败!', {icon: 1, time: 1000});                    }                },                error:function(data) {                    console.log(data.msg);                },            });        });    }
(3)返回部分(控制器里面)//   删除   public function del(Request $request){        $id = $request->input('id');        $res = QiyeModel::where('id',$id)->first();        if($res){            QiyeModel::where('id',$id)->delete();            return response()->json(['status'=>200,'msg'=>'删除成功']);        }else{            return response()->json(['status'=>500,'msg'=>'删除失败']);        }   }

2.ajax获取表单参数——————————————————
获取表单里面的所有参数$('#form_edit').serialize()
获取单个参数$('#id').val();
ID为foem_edit  tr为第五个  td为第四个 这条数据选中为true('#form_edit tr:nth-child(5) td:nth-child(4)').find('input').attr('checked','true');
跳转链接window.location.href="链接地址"
弹框 如果确定 继续执行confirm('确定要删除所选内容?');
重新加载该页面window.location.reload();
打印内容console.log();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ajax