jquery.from.js提交表单不选择文件报400

江辉a 2017-12-26 07:43:59
//提交数据
$(function(){
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSerialize:function(){
//alert("表单数据序列化前执行的操作!");
//$("#txt2").val("java");//如:改变元素的值
},
beforeSubmit:function(){
//alert("表单提交前的操作");
var file =$("input[type='file']")[0].files[0];
if(typeof(file) == "undefined"){
return true;
}
var filesize = file.size/1024/1024;
if(filesize > 10){
alert("文件大小超过限制,最多10");
return false;
}
//if($("#txt1").val()==""){return false;}//如:验证表单数据是否为空
},
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);

},
uploadProgress: function(event, position, total, percentComplete) {//上传的过程
//position 已上传了多少
//total 总大小
//已上传的百分数
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
//console.log(percentVal, position, total);
},
success: function(data) {//成功
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
if (data) {
swal({
title : "完成",
text : "编辑礼物成功",
type : "success"
},
function() {
var index = parent.layer
.getFrameIndex(window.name);
parent.layer.close(index);
});
} else {
swal({
title : "失败!",
text : "系统异常",
type : "success"
});
}

},
error:function(err){//失败
console.log(err)
alert("表单提交异常!"+err.msg);
},
complete: function(xhr) {//完成
status.html(xhr.responseText);
}
});

});
...全文
125 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Freefish1994 2017-12-27
  • 打赏
  • 举报
回复
配置文件有没有配置MultipartFile,没有的话加上试试

<bean name="multipartResolver"  
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
    <property name="defaultEncoding" value="UTF-8"></property>  
</bean>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧