jquery then

最近对前端进行优化,看了一下jquery then

发现有一点封装的比较好。 

$.ajax({url:'Abc',success:function(data){
    console.log(data);
}}).then(function(data){
    console.log("then="+data);
    return $.ajax({url:'Aaa',success:function(data){
         return data;
    }})
}).then(function(data){
    console.log("then3="+data);
}).done(function(data){
    console.log("done="+data);
}).then(function(data){
    console.log("then4="+data);
})

就是说不用调用子层,可以使用链式结构,太方便了。

猜你喜欢

转载自my.oschina.net/internetafei/blog/1802432