//提交数据
$(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);
}
});
});