我想将图像发送到服务器我的代码在 Chrome 版本 77.0.3865.90 中完美运行但在 Mozilla Firefox(版本 69.0.1)中,POST 方法更改为 GET 并出现此错误表单包含一个文件输入,但在表单上缺少 method=POST 和 enctype=multipart/form-data。不会发送文件。请求地址:http://localhost:3000/ ...请求方式:GET状态码: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" 因为csrf 令牌不能在带有 multipart/form-data enctype 的表单中实现
添加回答
举报
0/150
提交
取消