回答編集履歴
3
jsonの中身が間違っていたので修正
test
CHANGED
@@ -12,9 +12,9 @@
|
|
12
12
|
|
13
13
|
<li id="button_1" class="ajax_send" data-host-url="http://192.168.111.111/api" data-post-data="{btn:'A',pc:1,lang:'jp'}"><img src="/img/jp/JP1.png" width="345px" alt="" id="title_1"></li>
|
14
14
|
|
15
|
-
<li id="button_2" class="ajax_send" data-host-url="http://192.168.111.111/api" data-post-data="{btn:'
|
15
|
+
<li id="button_2" class="ajax_send" data-host-url="http://192.168.111.111/api" data-post-data="{btn:'B',pc:1,lang:'jp'}"><img src="/img/jp/JP2.png" width="345px" alt="" id="title_2"></li>
|
16
16
|
|
17
|
-
<li id="button_3" class="ajax_send" data-host-url="http://192.168.111.111/api" data-post-data="{btn:'
|
17
|
+
<li id="button_3" class="ajax_send" data-host-url="http://192.168.111.111/api" data-post-data="{btn:'C',pc:1,lang:'jp'}"><img src="/img/jp/JP3.png" width="345px" alt="" id="title_3"></li>
|
18
18
|
|
19
19
|
</ul>
|
20
20
|
|
2
ポイント追記
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
私ならこう書きます。
|
2
|
+
|
3
|
+
ポイントはHTML要素側に宛先URLとポストしたいデータを書けば、li要素がどんなに増えてもJavaScriptのコードは増やさなくて済むことです。
|
2
4
|
|
3
5
|
|
4
6
|
|
1
修正
test
CHANGED
@@ -30,8 +30,6 @@
|
|
30
30
|
|
31
31
|
var jsonObject = JSON.parse($(this).data('post-data')); // data-post-dataから送信したいjsonを引き出す
|
32
32
|
|
33
|
-
});
|
34
|
-
|
35
33
|
$.ajax({
|
36
34
|
|
37
35
|
url:hostUrl,
|
@@ -44,6 +42,8 @@
|
|
44
42
|
|
45
43
|
});
|
46
44
|
|
45
|
+
});
|
46
|
+
|
47
47
|
});
|
48
48
|
|
49
49
|
```
|