我想將圖像發(fā)送到服務(wù)器我的代碼在 Chrome 版本 77.0.3865.90 中完美運(yùn)行但在 Mozilla Firefox(版本 69.0.1)中,POST 方法更改為 GET 并出現(xiàn)此錯(cuò)誤表單包含一個(gè)文件輸入,但在表單上缺少 method=POST 和 enctype=multipart/form-data。不會(huì)發(fā)送文件。請(qǐng)求地址:http://localhost:3000/ ...請(qǐng)求方式:GET狀態(tài)碼:200<form class="form-horizontal" id="form" ><div class="col"> <label for="images" class="control-label">image</label> <input type="file" class="form-control" name="images" id="images" ></div><div class="form-group row"> <div class="col"> <button type="submit" class="btn btn-danger">Send</button> </div></div></form><script>document.getElementById('form').addEventListener('submit' , async function(event) {let images = document.querySelector('input[name="images"]');let formData = new FormData();formData.append('images' , images.files[0] );try { const response = await fetch('http://exampleurl.com/profile', { method: 'POST', headers: { 'X-Requested-With': 'XMLHttpRequest', 'X-CSRF-Token': "<%= req.csrfToken() %>", }, body: formData, credentials: 'same-origin' }); } catch (error) { console.error(error); } })</script>我不能在表單中使用 method ="POST" 和 enctype="multipart/form-data" 因?yàn)閏srf 令牌不能在帶有 multipart/form-data enctype 的表單中實(shí)現(xiàn)
當(dāng)我想獲取 formData 時(shí),POST 轉(zhuǎn)換為 GET 嗎?
蝴蝶刀刀
2021-10-29 16:33:03