含有文件的form表单用jquery提交

近期做项目遇到此问题,含有文件上传的form表单用ajaxSubmit提交,在此记录下,代码如下:


<form id="excelForm" name="excelForm" enctype="multipart/form-data" method="post">
<table>
<tr>
<td width="120" align="right" bgcolor="#f4f4f4">选择文件:<span style='color:red;'></span></td>
<td><input type="file" name="file" id="file"></td>
<td><input type="button" value="导入" οnclick="excelImport()"></td>
</tr>
<tr>
<td width="120" align="right" bgcolor="#f4f4f4">示例模板:</td>
   <td bgcolor="white">
    <img height="20" with=" 30" src="/static/images/slmb.png"/><a href="javascript:location=encodeURI(encodeURI('/servlet/download.do?file_path=电话号码导入模板.xls&file_name=/hgj/hgjSms/telNo.xlsx'))">点击下载</a>
   </td>
</tr>
</table>
</form>


function excelImport(){

//校验是否选择文件
var file = $("#file").val();
if(file == null || file == ""){
alert("请选择文件!");
return false;
}

$("#excelForm").ajaxSubmit({
url : '/hgjSms/excelImport.htm',
type : 'POST',
success : function(data){
var obj = eval("("+data+")");
if(obj.resultType == "-1"){
alert("文件中以下行中的号码格式不正确:" + obj.resultStr);
return;
}else if(obj.resultType == "-2"){
alert("选择的文件未读到手机号码");
return;
}else if(obj.resultType == "-3"){
alert("系统异常");
return;
}else {
$("#checkCount").html(obj.memberCount);
          $("#sendCount").html(obj.memberCount);
          $("input[name='tel']").each(function(){
        $(this).attr('disabled',false);
    });
}
}
})
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值