这里我使用xmlHttpRequest和二进制数据发送帖子数据。但是xhr.send(formdata);给出无效参数的错误。
var formData = {};
formData.files= options[0].file;
var bodyValues = options[0];
delete bodyValues.file;
formData.bodyData=bodyValues;
var xhr = new XMLHttpRequest();
xhr.open('POST', config.javaServer+config.baseUrl+AccountNumber+"/upload/"+config.lowerClaimDocUplTs, true);
xhr.setRequestHeader('claimNum',ClaimNumber);
xhr.onload = function () {
// do something to response
console.log(this.responseText);
console.log("success");
var uploadRespo = $.parseJSON(this.responseText);
if(uploadRespo.error){
console.log("error");
}else if(uploadRespo.data.status=="200"){
console.log("success");
}else{
console.log("error");
}
};
xhr.onerror = function () {
console.log("error upload");
console.log("error");
alert("upload failed");
};
xhr.send(formData);