teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

4

誤記の訂正

2019/07/01 14:18

投稿

syuus
syuus

スコア403

answer CHANGED
@@ -26,7 +26,7 @@
26
26
  url: './request.php',
27
27
  type: 'POST',
28
28
  data: {
29
- 'test': 'data',
29
+ test: 'data',
30
30
  },
31
31
  }).done(() => {
32
32
  $('#text').text('成功');

3

func_exampleの変更

2019/07/01 14:18

投稿

syuus
syuus

スコア403

answer CHANGED
@@ -17,15 +17,21 @@
17
17
  document.getElementById('button').addEventListener('click', () => {
18
18
  var result = window.confirm('「OK」か「キャンセル」を選んでください。');
19
19
  if (result) {
20
- func_example('「OK」が選択されました。');
20
+ func_example();
21
- } else {
22
- func_example('「キャンセル」が選択されました。');
23
21
  }
24
22
  });
25
23
 
26
- function func_example(text) {
24
+ function func_example() {
25
+ $.ajax({
26
+ url: './request.php',
27
+ type: 'POST',
28
+ data: {
29
+ 'test': 'data',
30
+ },
27
- $(function() {
31
+ }).done(() => {
28
- $('#text').text(text);
32
+ $('#text').text('成功');
33
+ }).fail(() => {
34
+ $('#text').text('失敗');
29
35
  });
30
36
  }
31
37
  </script>

2

質問内容にきちんと回答できていなかったのを訂正

2019/07/01 14:14

投稿

syuus
syuus

スコア403

answer CHANGED
@@ -8,16 +8,26 @@
8
8
  <meta charset="UTF-8">
9
9
  </head>
10
10
  <body>
11
+ <div id="text"></div>
11
12
  <button id="button">クリック</button>
13
+ <script src="https://code.jquery.com/jquery-3.4.1.js"
14
+ integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
15
+ crossorigin="anonymous"></script>
12
16
  <script>
13
17
  document.getElementById('button').addEventListener('click', () => {
14
18
  var result = window.confirm('「OK」か「キャンセル」を選んでください。');
15
19
  if (result) {
16
- console.log('「OK」が選択されました。');
20
+ func_example('「OK」が選択されました。');
17
21
  } else {
18
- console.log('「キャンセル」が選択されました。');
22
+ func_example('「キャンセル」が選択されました。');
19
23
  }
20
24
  });
25
+
26
+ function func_example(text) {
27
+ $(function() {
28
+ $('#text').text(text);
29
+ });
30
+ }
21
31
  </script>
22
32
  </body>
23
33
  </html>

1

リンクの訂正

2019/06/30 15:09

投稿

syuus
syuus

スコア403

answer CHANGED
@@ -1,6 +1,6 @@
1
1
  `window.confirm()` は「OKのときは `true` 」「キャンセルのときは `false` 」の真偽値が返ってくるので、それで条件を分岐すれば可能です。
2
2
 
3
- https://developer.mozilla.org/ja/docs/Web/API/Window/confirm
3
+ [window.confirm - Web API | MDN](https://developer.mozilla.org/ja/docs/Web/API/Window/confirm)
4
4
 
5
5
  ```html
6
6
  <!DOCTYPE html>