如何针对屏幕尺寸为元素制作动态宽度?-英雄云拓展知识分享
290
2024-01-21
我正在学习使用node.js和multer上传文件。我已配置了Main App.js文件,和upload.html。
我的表格:
<form id="uploadForm" action="/uploads" enctype="multipart/form-data" method="post"><input id="upload-input" type="file" name="uploads" multiple>
<button class="upload-button" type="button">File</button>

</form>
和我试图处理情势数据并使用fetch()发布的脚本。
uploadInput.addEventListener('change', function() {let files = event.target.files;
if(files.length > 0) {
let formData = new FormData();
for(let i = 0; i < files.length; i++) {
let file = files[i];
formData.append('uploads', file);
}
fetch('uploads', {
method: 'POST',
body: formData
})
.then(res => res.json(), error => error.message);
}
});
文件正在上传,除两个毛病以外,一切都很好。首先在阅读器控制台显示:
uploader:1 Uncaught (in promise) SyntaxError: Unexpected token s in JSON at position 0
在WebStorm IDE控制台中排名第2:
(node:51729) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
您是不是知道为何会出现毛病,而一切正常?
看起来问题是 .then(res => res.json(), error => error.message);
JSON解析毛病几近可以肯定是由于您没有回复JSON。很难说出为何您要确切取得折旧正告,但这可能与您的 .then()
称呼。对二者,请做一些有用的结果,例如 console.log(res)
和 console.log(error)
.
免责声明:
本网址(www.yingxiongyun.com)发布的材料主要源于独立创作和网友匿名投稿。此处提供的所有信息仅供参考之用。我们致力于提供准确且可信的信息,但不对材料的完整性或真实性作出任何保证。用户应自行验证相关信息的正确性,并对其决策承担全部责任。对于由于信息的错误、不准确或遗漏所造成的任何损失,本网址不承担任何法律责任。本网站所展示的所有内容,如文字、图像、标志、音频、视频、软件和程序等的版权均属于原创作者。如果任何组织或个人认为网站内容可能侵犯其知识产权,或包含不准确之处,请即刻联系我们进行相应处理。
发表评论
暂时没有评论,来抢沙发吧~