回答編集履歴

1

調整

2023/04/28 06:08

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -1 +1,29 @@
1
1
  単純に従業員情報を送った際に、すでにデータが登録されていたらエラーステータスを返すか、エラーでおわった旨のメッセージを返せばよいと思います
2
+
3
+ # 参考
4
+ ```javascript
5
+ <?PHP
6
+ $test=filter_input(INPUT_POST,"test");
7
+ if(!is_null($test)){
8
+ if($test=="1"){
9
+ die("success");
10
+ }else if($test=="2"){
11
+ die("fail");
12
+ }else{
13
+ header('HTTP/1.1 500 Internal Server Error');
14
+ die("500 err");
15
+ }
16
+ }
17
+ ?>
18
+ <script>
19
+ const body=new FormData();
20
+ const method="post";
21
+ const func=()=>fetch('',{body,method}).then(res=>res.text().then(body =>({ body,ok:res.ok,status:res.status}))).then(({body,ok,status})=>{if(!ok) throw new Error(status);return body}).then(txt=>console.log(txt)).catch(err=>console.error(err));
22
+ body.append('test',1);
23
+ func();
24
+ body.set('test',2);
25
+ func();
26
+ body.set('test',3);
27
+ func();
28
+ </script>
29
+ ```