JavaScript——JQuery AJAX鏈式編程(流式編程)DEMO

基本概念

鏈式編程:設計模式之一

DEMO

doSubmit: function(){ 
 return $.ajax({
       url: url,
       type: 'post',
       data: $("#fm").serialize(),
       dataType: 'html'
   }).then(function(data){
       toastr.error(" 提交成功", "操作成功");
   }, function(){
       toastr.error("提交失敗", "操作失敗");
   });
}
$.ajax("test.html")
.done(
    function(){
        console.log("success");
    }
)
.fail(
    function(){
        console.log("error");
    }
);
$.when($.ajax("test1.html"), $.ajax("test2.html"))
.done(function(){console.log("success");})
.fail(function(){console.log("error");});

參考文章

https://blog.csdn.net/qq_27970999/article/details/78718023

https://blog.csdn.net/zhouziyu2011/article/details/70257687

https://blog.csdn.net/weixin_33935505/article/details/89527694

https://www.cnblogs.com/lvdabao/p/jquery-deferred.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章