jQuery使用ajax

1.导入jQuery的js库

 

2.jQuery发送单一的get请求

$.get(
    url:'接口地址',
    data:{
        id:1,
        name:2,
        ......
    }
    function(res){
        // res是服务器返回的数据
    }
)

 

 

 

3.jQuery发送单一的post请求
$.post(
    url:'接口地址',
    data:{
        id:1,
        name:'哈哈哈',
        ......
    }
    function(res){
        // res是服务器返回的数据
    }
)

 

 

 

4.jQuery发送符合Ajax请求
$.ajax({
    type:'GET or POST',
    url:'接口地址',
    data:{
        id:1,
        name:'哈哈哈',
        ......
    }
    success:function(res){
        // res是服务器返回的数据
    }
})

 

 

posted @ 2022-08-29 21:54  漫步火星  阅读(196)  评论(0编辑  收藏  举报