--form表单使用ajax提交,获取回调函数

//页面部分
<div class="top-left">
<form id="domainExtendMsgSubmitForm" action="<%=path%>/domain/domainExtendMsgImport.htm"                 enctype="multipart/form-data" method="post">
<input type="file" name="file" style="color: white;"  />
<input type="hidden" name="pageCount" value="${page.rowCount }"  />
<input type="button" value="导入excel" onclick="domainExtendMsgSubmit()"/><span style="font-size:10px;             color: white; ">(仅支持xls格式)</span>
</form>
</div>

//js部分:
function domainExtendMsgSubmit() {
//        $("#domainExtendMsgSubmitForm").submit();

//domainExtendMsgSubmitForm为form表单id

    var formData = new FormData($("#domainExtendMsgSubmitForm")[0]);
    //formData.append('sgid',_sgId); 添加表单之外的参数
    $.ajax({
               url: '<%=path%>/domain/domainExtendMsgImport.htm',
               type: 'POST'
               data: formData, 
               cache: false,
               dataType: "json", //预期服务器返回的数据类型
                                //注意这里一定要设置contentType:false,不然会默认为传的是字符串,这样文件就传不过去了
               contentType: false
               processData: false
               success: function (data) {
                   if (data.code == 0) {
                        window.location.reload();
                   } else {
                        alert(data.msg);
                        window.location.reload();
                   }
               }, 
               error: function (data) {
                   alert(data.msg);
               } 
          });
      }

阅读更多
个人分类: 前端
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭