回答編集履歴
2
chousei
test
CHANGED
@@ -46,6 +46,12 @@
|
|
46
46
|
|
47
47
|
const method = "POST";
|
48
48
|
|
49
|
+
/*
|
50
|
+
|
51
|
+
const headers = {'Content-Type': 'multipart/form-data'}; //うまく渡らない
|
52
|
+
|
53
|
+
*/
|
54
|
+
|
49
55
|
const headers = {};
|
50
56
|
|
51
57
|
const body=new FormData(e.target);
|
1
調整
test
CHANGED
@@ -25,3 +25,61 @@
|
|
25
25
|
</form>
|
26
26
|
|
27
27
|
```
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
# fetch
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```javascript
|
36
|
+
|
37
|
+
<script>
|
38
|
+
|
39
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
40
|
+
|
41
|
+
document.querySelector('form').addEventListener('submit',e=>{
|
42
|
+
|
43
|
+
e.preventDefault();
|
44
|
+
|
45
|
+
const url="send.php";
|
46
|
+
|
47
|
+
const method = "POST";
|
48
|
+
|
49
|
+
const headers = {};
|
50
|
+
|
51
|
+
const body=new FormData(e.target);
|
52
|
+
|
53
|
+
fetch(url,{method, headers, body}).then(res=>res.text()).then(console.log);
|
54
|
+
|
55
|
+
});
|
56
|
+
|
57
|
+
});
|
58
|
+
|
59
|
+
</script>
|
60
|
+
|
61
|
+
<form method="post" enctype="multipart/form-data">
|
62
|
+
|
63
|
+
<input type="text" name="hoge" value="123"><br>
|
64
|
+
|
65
|
+
<input type="file" name="fuga"><br>
|
66
|
+
|
67
|
+
<input type="submit" value="send">
|
68
|
+
|
69
|
+
</form>
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
- send.php
|
74
|
+
|
75
|
+
```PHP
|
76
|
+
|
77
|
+
<?PHP
|
78
|
+
|
79
|
+
print_r($_POST);
|
80
|
+
|
81
|
+
print_r($_FILES);
|
82
|
+
|
83
|
+
?>
|
84
|
+
|
85
|
+
```
|