回答編集履歴

3

ちょうせい

2019/07/04 01:27

投稿

yambejp
yambejp

スコア114856

test CHANGED
@@ -20,19 +20,25 @@
20
20
 
21
21
  for(var i=1;i<1000;i+=100){
22
22
 
23
- await fetch(url +
23
+ await fetch(
24
24
 
25
- "?beginIndex=" + i +
25
+ url +
26
26
 
27
- "&endIndex=" + (i+99) +
27
+ "?beginIndex=" + i +
28
28
 
29
- "&nocash="+new Date().getTime()
29
+ "&endIndex=" + (i+99) +
30
30
 
31
- ).then(
31
+ "&nocash="+new Date().getTime()
32
32
 
33
- response=>response.json()
33
+ ).then(
34
34
 
35
+ response=>response.json()
36
+
37
+ ).then(
38
+
35
- ).then(console.log);
39
+ console.log
40
+
41
+ );
36
42
 
37
43
  }
38
44
 

2

ちょうせい

2019/07/04 01:27

投稿

yambejp
yambejp

スコア114856

test CHANGED
@@ -20,21 +20,19 @@
20
20
 
21
21
  for(var i=1;i<1000;i+=100){
22
22
 
23
- await new Promise(resolve=>{
23
+ await fetch(url +
24
24
 
25
- fetch(url + "?beginIndex=" + i + "&endIndex=" + (i+99)+"&nocash="+new Date().getTime())
25
+ "?beginIndex=" + i +
26
26
 
27
- .then(response=>response.json())
27
+ "&endIndex=" + (i+99) +
28
28
 
29
- .then(json=>{
29
+ "&nocash="+new Date().getTime()
30
30
 
31
- console.log(json);
31
+ ).then(
32
32
 
33
- resolve();
33
+ response=>response.json()
34
34
 
35
- });
35
+ ).then(console.log);
36
-
37
- });
38
36
 
39
37
  }
40
38
 

1

調整

2019/07/04 01:25

投稿

yambejp
yambejp

スコア114856

test CHANGED
@@ -1 +1,63 @@
1
1
  単純にhttps://example.testがCORS制約にかかってエラーになっているのでは?
2
+
3
+
4
+
5
+ # sample
6
+
7
+ 読み終わってから次を読むasync/awaitのサンプル
8
+
9
+
10
+
11
+ - mypage.html
12
+
13
+ ```javascript
14
+
15
+ <script>
16
+
17
+ var url="jsontest.php";
18
+
19
+ (async ()=>{
20
+
21
+ for(var i=1;i<1000;i+=100){
22
+
23
+ await new Promise(resolve=>{
24
+
25
+ fetch(url + "?beginIndex=" + i + "&endIndex=" + (i+99)+"&nocash="+new Date().getTime())
26
+
27
+ .then(response=>response.json())
28
+
29
+ .then(json=>{
30
+
31
+ console.log(json);
32
+
33
+ resolve();
34
+
35
+ });
36
+
37
+ });
38
+
39
+ }
40
+
41
+ })();
42
+
43
+ </script>
44
+
45
+ ```
46
+
47
+ - jsontest.php
48
+
49
+ ※時間差がわかるように2秒ずつウェイトをかけています
50
+
51
+
52
+
53
+ ```PHP
54
+
55
+ <?PHP
56
+
57
+ sleep(2);
58
+
59
+ print json_encode(range($_GET["beginIndex"],$_GET["endIndex"]));
60
+
61
+ ?>
62
+
63
+ ```