回答編集履歴

1

調整

2022/08/04 00:44

投稿

yambejp
yambejp

スコア114572

test CHANGED
@@ -4,3 +4,31 @@
4
4
  $id = $_POST['id'];
5
5
  ```
6
6
  では?
7
+
8
+ # 参考
9
+ 呼び出しファイルを間違えているとかそういう凡ミスのような気がします
10
+ 自分自身にpostして試してください
11
+ ```PHP
12
+ <?PHP
13
+ if($_SERVER["REQUEST_METHOD"]=="POST"){
14
+ $id = $_POST['id'];
15
+ $list = array("id" => $id, "hoge" => "hogehoge");
16
+ header("Content-type: application/json; charset=UTF-8");
17
+ echo json_encode($list);
18
+ exit;
19
+ }
20
+ ?>
21
+ <script>
22
+ window.addEventListener('DOMContentLoaded', ()=>{
23
+ sendBtn.addEventListener('click',()=>{
24
+ const body=new FormData();
25
+ body.append('id',twid.value);
26
+ fetch("",{method:"post",body}).then(res=>res.json()).then(console.log);
27
+ });
28
+ });
29
+ </script>
30
+ <form>
31
+ <input id="twid" name="twid" type="text" placeholder="ID">
32
+ <button type="button" id="sendBtn">送信</button>
33
+ </form>
34
+ ```