jquery(五)Ajax请求

在jQuery中AJAX的写法有3种,$ajax,$post,$get这三种。其中$post和$get是简易写法,高层的实现,在调用他们的时候,会运行底层封装好的$ajax。

ajax写法

$.ajax({
    url:"http://www.microsoft.com",    //请求的url地址
    dataType:"json",   //返回格式为json
    async:true,//请求是否异步,默认为异步,这也是ajax重要特性
    data:{"id":"value"},    //参数值
    type:"GET",   //请求方式
    beforeSend:function(data){
        //请求前的处理
    },
    success:function(req){
        //请求成功时处理
    },
    complete:function(data){
        //请求完成的处理
    },
    error:function(data){
        //请求出错处理
    }
});

get请求

 $.get("url",{id:1},function(data){
                    
  })

POST请求

 $.post("url",{id:1},function(data){

   })

猜你喜欢

转载自blog.csdn.net/baiyan3212/article/details/83141914