javascript xhr file upload without jQuery

て烟熏妆下的殇ゞ 提交于 2019-12-03 22:04:35
formData.append( ???, ??? ); // file

Yes, a file. There is an example in the MDN documentation:

formData.append('userpic', myFileInput.files[0], 'chris.jpg');
xhr.setRequestHeader('Content-type', 'multipart/form-data; charset=UTF-8');

Remove that. XHR will generate the correct content type for you. Doing it manually will fail to include the (essential) boundary information.

and second, if i want to send "formData" via XHR, do i just put "formData" variable into "xhr.send" method like this?

Yes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!