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);
}
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你使用
send发送formdata的时候不需要在设置form-data的头了,设置了反而有问题。