ajax请求的两种写法

1. 回调

最常写的方式,成功失败处理以回调方式传入。

$.ajax({

   ajax参数...

   success : xxxxxx

   error: xxxxxx

});

2. Deferred方式

ajax调用本身返回就是一个Deferred对象,成功失败回调不以参数传入。

$.ajax({

   ajax参数...

}).then(function(res){

  //成功处理片段

},function(err){

  //失败处理片段

});

或者

$.ajax({
    url:"1.json",
    type:"get"    
}).done(function(data){
    
}).fail(function(){
    
});

猜你喜欢

转载自blog.csdn.net/weixin_42776027/article/details/102929490
今日推荐