<form action="http://192.168.1.165:8088/upload" method="post"
enctype="multipart/form-data">
<input type="file" value='选择文件' name='file' >
<input type="submit" value='提交'>
</form>
1.表单提交在Network的xhr是看不到的,要选择All
2.表单提交会刷新页面
3.跨域问题可以后端设置access-control-allow-origin,以及access-control-allow-methos;但是methos不包含formData,所以客户端需要改为POST提交,代码如下,http传输中的request payload内容和表单是一致的
var url = "http://192.168.1.165:8088/upload";
for(var i=0;i<fileList.length;i++){
var formData = new FormData();
formData.append("file", fileList[i]);
$.ajax({
type: "POST",
url: url,
data:formData,
contentType: false,
processData: false,
success: function (data) {
if(uploadImgUrl){
uploadImgUrl=uploadImgUrl+','+data
}else{
uploadImgUrl=data
}
console.log('uploadImgUrl :', uploadImgUrl);
},
failed: function () {
layer.alert("系统出错!");
}
});
}