您好,欢迎访问一九零五行业门户网

javascript - js上传文件,使用了formdata对象,可若设置了setRequesetHeader,会失败是怎么回事?

formdata.append('images',type); var xhr=new xmlhttprequest(); xhr.open('post',path,true); // xhr.setrequestheader('content-type','multipart/form-data'); 若这儿一旦设置就会上传失败,这是怎么回事?难道是类型设置错误? xhr.send(formdata); xhr.onreadystatechange=function(){ if (this.readystate===4 && this.status===200) { if (this.responsetext) { var data=this.responsetext; console.log(this.responsetext); } } }

回复内容: formdata.append('images',type); var xhr=new xmlhttprequest(); xhr.open('post',path,true); // xhr.setrequestheader('content-type','multipart/form-data'); 若这儿一旦设置就会上传失败,这是怎么回事?难道是类型设置错误? xhr.send(formdata); xhr.onreadystatechange=function(){ if (this.readystate===4 && this.status===200) { if (this.responsetext) { var data=this.responsetext; console.log(this.responsetext); } } }

你使用 send 发送 formdata 的时候不需要在设置 form-data 的头了,设置了反而有问题。
其它类似信息

推荐信息