回答編集履歴

1

追記

2019/01/08 03:42

投稿

yambejp
yambejp

スコア114867

test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  ajaxのthenの中で、promiseで順番を守って下さい
28
28
 
29
-
29
+ (追記:よく考えたらその必要はない)
30
30
 
31
31
  ```javascript
32
32
 
@@ -51,3 +51,43 @@
51
51
 
52
52
 
53
53
  ```
54
+
55
+
56
+
57
+ # 追記
58
+
59
+
60
+
61
+ thenで連続してつなぐならこう書けますね
62
+
63
+
64
+
65
+ ```javascript
66
+
67
+ $(function(){
68
+
69
+ var d=Array(3).fill(null).map(function(){return $.Deferred()});
70
+
71
+ $.ajax({
72
+
73
+ }).then(function(){
74
+
75
+ return d[0].promise(setTimeout(function(){console.log(1);d[0].resolve();},300));
76
+
77
+ }).then(function(){
78
+
79
+ return d[1].promise(setTimeout(function(){console.log(2);d[1].resolve();},200));
80
+
81
+ }).then(function(){
82
+
83
+ return d[2].promise(setTimeout(function(){console.log(3);d[2].resolve();},100));
84
+
85
+ }).then(function(){
86
+
87
+ setTimeout(function(){console.log(4);},100);//最後の処理はpromise不要
88
+
89
+ });
90
+
91
+ });
92
+
93
+ ```