the request was rejected because no multipart boundary was found??求解
2016-08-25 15:24
1261 查看
最近有个项目要求跨域post来上传文件,但是运行代码以抛出the request was rejected because no multipart boundary was found异常,以下是jsp页面的代码,哪位大神可以告诉我是怎么回事,该如何修改代码?
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<title>Upload</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
$(function(){
$('.sumbit').click(function(){
var formData = new FormData($('#form1'));
var jsonuserinfo = $('#form1').serializeObject();
alert(JSON.stringify(jsonuserinfo));
alert(formData);
$.ajax({
type: "post", // 或者 "get"
url: "http://localhost:8020/SmartHomeCloudService/DeviceDriver/Upload",
dataType: "json",
data:formData,
contentType:"multipart/form-data",
crossDomain:true,//跨域
processData:false,
success:function(){
alert("success");
},
error:function(){
alert("error");
}
});
});
});
</script>
</head>
<body>
<h3 align="center">jquery Ajax</h3>
<iframe name="upload" style="display:none"></iframe>
<form id="form1" name="form1" method="post" target="upload" action="" encType="multipart/form-data">
<p></p>
file:<input type="file" name="upload_file" id="upload_file" />
<p></p>
<input class="sumbit" type="button" value="提交">
</form>
</body>
</html>
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<title>Upload</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
$(function(){
$('.sumbit').click(function(){
var formData = new FormData($('#form1'));
var jsonuserinfo = $('#form1').serializeObject();
alert(JSON.stringify(jsonuserinfo));
alert(formData);
$.ajax({
type: "post", // 或者 "get"
url: "http://localhost:8020/SmartHomeCloudService/DeviceDriver/Upload",
dataType: "json",
data:formData,
contentType:"multipart/form-data",
crossDomain:true,//跨域
processData:false,
success:function(){
alert("success");
},
error:function(){
alert("error");
}
});
});
});
</script>
</head>
<body>
<h3 align="center">jquery Ajax</h3>
<iframe name="upload" style="display:none"></iframe>
<form id="form1" name="form1" method="post" target="upload" action="" encType="multipart/form-data">
<p></p>
file:<input type="file" name="upload_file" id="upload_file" />
<p></p>
<input class="sumbit" type="button" value="提交">
</form>
</body>
</html>
相关文章推荐
- XHR异步上传文件报错: “the request was rejected because no multipart boundary was found”
- 使用postman模拟上传文件到springMVC的坑:the request was rejected because no multipart boundary was found
- feign client multipart feign调用服务上传图片 报错 the request was rejected because no multipart boundary was
- struts上传图片过大限制:the request was rejected because its size (2407044) exceeds the configured m
- Rejected because no crossdomain.xml policy file was found
- struts2出现 the request was rejected because its size (XXXX) exceeds the configured maximum (XXXX)
- the request was rejected because its size (4652587) exceeds the configured maximum (2097152)
- the request was rejected because its size (***) exceeds the configured maximum (2097152) 上传不成功
- Rejected because no crossdomain.xml policy file was found
- Struts中the request was rejected because its size (***) exceeds the configured ma
- 浅谈对struts2.2 the request was rejected because its size (XXXX) exceeds the configured maximum (XXXX)错
- 关于文件上传遇到的问 no multipart boundary was found
- The drive could not be mapped because no network was found.
- org.apache.commons.fileupload.FileUploadBase$UnknownSizeException: the request was rejected because its size is unknown
- Struts中the request was rejected because its size (***) exceeds the configured ma
- struts2出现 the request was rejected because its size (XXXX) exceeds the configured maximum (XXXX)
- the request was rejected because its size ..exc
- Your build settings specify a provisioning profile with the UUID, no provisioning profile was found
- HTTP Status 403 - Invalid CSRF Token 'null' was found on the request parameter '_csrf'...
- [Jenkins]Error:403 No valid crumb was included in the request