回答編集履歴
2
chousei
answer
CHANGED
@@ -22,6 +22,9 @@
|
|
22
22
|
e.preventDefault();
|
23
23
|
const url="send.php";
|
24
24
|
const method = "POST";
|
25
|
+
/*
|
26
|
+
const headers = {'Content-Type': 'multipart/form-data'}; //うまく渡らない
|
27
|
+
*/
|
25
28
|
const headers = {};
|
26
29
|
const body=new FormData(e.target);
|
27
30
|
fetch(url,{method, headers, body}).then(res=>res.text()).then(console.log);
|
1
調整
answer
CHANGED
@@ -11,4 +11,33 @@
|
|
11
11
|
<input type="file" name="fuga"><br>
|
12
12
|
<input type="submit" value="send">
|
13
13
|
</form>
|
14
|
+
```
|
15
|
+
|
16
|
+
# fetch
|
17
|
+
|
18
|
+
```javascript
|
19
|
+
<script>
|
20
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
21
|
+
document.querySelector('form').addEventListener('submit',e=>{
|
22
|
+
e.preventDefault();
|
23
|
+
const url="send.php";
|
24
|
+
const method = "POST";
|
25
|
+
const headers = {};
|
26
|
+
const body=new FormData(e.target);
|
27
|
+
fetch(url,{method, headers, body}).then(res=>res.text()).then(console.log);
|
28
|
+
});
|
29
|
+
});
|
30
|
+
</script>
|
31
|
+
<form method="post" enctype="multipart/form-data">
|
32
|
+
<input type="text" name="hoge" value="123"><br>
|
33
|
+
<input type="file" name="fuga"><br>
|
34
|
+
<input type="submit" value="send">
|
35
|
+
</form>
|
36
|
+
```
|
37
|
+
- send.php
|
38
|
+
```PHP
|
39
|
+
<?PHP
|
40
|
+
print_r($_POST);
|
41
|
+
print_r($_FILES);
|
42
|
+
?>
|
14
43
|
```
|