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

江辉a 2017-12-27 09:17:35
//提交数据
$(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);
}
});

});
...全文
264 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianfang 2017-12-29
  • 打赏
  • 举报
回复
我感觉是js没有传输file文件数据 你可以用浏览器的调试器查看request数据

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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