Ajax

ajax
局部刷新页面
*底层接口
$.ajax({}) 只接收一个参数->对象
ajax请求的格式:
$.ajax({
url, //请求的后台接口
method, //请求方式post,get,delete,put
data, //发送给后台的数据
contentType, //请求头的格式
success:function(res){}, //成功的回调函数,res表示成功的回调函数所返回的参数
error:function(err){}, //失败的回调函数
})

      eg:
        //底层接口,get有参
        // ajax表示函数,ajax()表示函数的调用
        // $.ajax({
        //     url:"http://47.93.255.92:5588/category/findAll",
        //     method:'GET',
        //     data:{},
        //     success:function(res){
        //         console.log(res)
        //     }
        
快捷方式
    $get(url,data,function(){})
    $post(url,data,function(){})

    //快捷方式,get无参,设置请求头的时候不可以使用
    $.get('http://47.93.255.92:5588/category/findAll',{},function(res){
        console.log(res)
    })

    // 快捷方式的get有一个参
    // 1
    // var id = 202426;
    // $.get('http://47.93.255.92:5588/comment/deleteById?id='+id,function(res){
    //     console.log(res)
    // })
    // 2
    // var id = 202449;
    // $.get('http://47.93.255.92:5588/comment/deleteById',{id:id},function(res){
    //     console.log(res)
    // })

    // 快捷方式的get有两个参数
    // $.get('http://47.93.255.92:5588/customer/recharge',{id:28,money:100},function(res){
    //   console.log(res);
    // })

    // 快捷方式,post有参
    // $.POST('http://47.93.255.92:5588/comment/query',{page:0,pageSize:10},function(res){
    //         console.log(res)
    //     })

拓展
  ajaxSetup()
      ajaxSetup()
        配置全局的设置
            ajaxSetup({
                headers:{
                    'Authorization':token
                }
            })
  ajaxStart()
  ajaxSuccess()
    //给button添加点击事件
     $('button').click(function(){
        $.get('http://47.93.255.92:5588/category/findAll',function(res){
            console.log(res)
        })
    })
    //点击开始时,div的样式设置为block显示
    $(document).ajaxStart(function(){
        $('div').attr('style','display:block')
    })
    //点击成功时,div的样式设置为none隐藏
    $(document).ajaxSuccess(function(){
        $('div').attr('style','display:none')
    })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值