回答編集履歴

3

fetch

2019/08/01 04:39

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -68,7 +68,7 @@
68
68
 
69
69
  <script>
70
70
 
71
- window.addEventListener('DOMContentLoaded', function(e){
71
+ window.addEventListener('DOMContentLoaded', ()=>{
72
72
 
73
73
  const location=document.querySelector('#hoge').dataset['location'];
74
74
 

2

chousei

2019/08/01 04:39

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -59,3 +59,33 @@
59
59
  <div id="hoge" data-user_id="1" data-location="2">hoge</div>
60
60
 
61
61
  ```
62
+
63
+
64
+
65
+ # fetch版
66
+
67
+ ```javascript
68
+
69
+ <script>
70
+
71
+ window.addEventListener('DOMContentLoaded', function(e){
72
+
73
+ const location=document.querySelector('#hoge').dataset['location'];
74
+
75
+ const user_id=document.querySelector('#hoge').dataset['user_id'];
76
+
77
+ const str = `/users/locations/${location}/coming_locations/${user_id}/`;
78
+
79
+ console.log(str);
80
+
81
+ const method = "patch";
82
+
83
+ fetch(str, {method}).then(data=>data.text()).then(console.log);
84
+
85
+ });
86
+
87
+ </script>
88
+
89
+ <div id="hoge" data-user_id="1" data-location="2">hoge</div>
90
+
91
+ ```

1

chousei

2019/08/01 04:38

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -23,3 +23,39 @@
23
23
  もしくは今は普通に動いているならなんらかの勘違いがあったか
24
24
 
25
25
  レベルの話ではないでしょうか?
26
+
27
+
28
+
29
+ # 調整
30
+
31
+
32
+
33
+ ```javascript
34
+
35
+ <script>
36
+
37
+ $(function(){
38
+
39
+ const location=$('#hoge').data('location');
40
+
41
+ const user_id=$('#hoge').data('user_id');
42
+
43
+ var str = `/users/locations/${location}/coming_locations/${user_id}/`;
44
+
45
+ console.log(str);
46
+
47
+ $.ajax({
48
+
49
+ url:str,
50
+
51
+ type:'patch',
52
+
53
+ });
54
+
55
+ });
56
+
57
+ </script>
58
+
59
+ <div id="hoge" data-user_id="1" data-location="2">hoge</div>
60
+
61
+ ```