ajaxForm.submit()

<form id="Excelform" method="post"  enctype="multipart/form-data" style="display: inline-block;">
    <div class="excelupload" style="display:none;z-index:100;">
        <div class="excelHead">
            <label style="float:left;color: #49d6ff;font-size: 18px;font-weight: bold;margin-left:158px; margin-top:20px;">数据导入</label>
            <img src="~/Scripts/statics/images/X.png" style="float:right; margin-top:4px;margin-right:4px;opacity:.5; cursor: pointer;" id="close_btn" />
        </div>
        <div class="set_date">
            <label>选择时间:</label>
            <input type="text" class="select_butn layui-input" style="font-size:14px;text-align:left;opacity:.7;border:1px solid #2D9EF3;" id="useDate" name="UCE512" value="" readonly required placeholder="日期" />
        </div>
        <div class="upload_file">
            <input type="file" class="filess" id="attend-files" style="display:none;" name="File"  value=" " onchange="addFiles();" />
            <label class="filetext" style="color:white;font-size:14px;width:30px;">选择文件:</label>
            <u class="change_btn" style="color:white;" >上传文件</u>
        </div>
        <div class="file_import" style="margin-left: 160px;"><button type="button" onclick="btnClick();">导入</button></div>
    </div>
</form>
//提交表单
function btnClick()
{
    //年月和文件不能为空
    var ym = $('#useDate').val();
    var file = $('.filess').val();
    if (ym === "" || file === "") {
        console.log("不能为空");
         
        return;
    }
    //调用文件上传
    FileUpload();
}
function FileUpload () {
    //SystemNotice.show({
    //    systitle: "温馨提示", systext: "正在上传",
    //});
    console.log("正在上传中");
    //表格上传    
    var options = {
        type: "post",
        url: 'http://localhost:62101/StatisticsService/JobIntroduction/Unemployment/v1/UploadExcel',
        success: function (resultjson) {
            console.log(resultjson);
            if (resultjson.IsOK) {
                if (resultjson.RowCount == "0") {
                    console.log("表中没有数据!");
                }
                console.log("上传成功");
                //上传成功后 把控件还原初始状态
                //按钮变色
                $('#useDate').attr('value', '');
                $('.filess').attr('value', '');


            } else {
                //上传失败后 把控件还原初始状态


                if (resultjson.Message != null || resultjson.Message != "" || resultjson.Message != undefined) {
                    //SystemNotice.show({
                    //    systitle: "温馨提示", systext: resultjson.Message,
                    //});
                } else {
                    //SystemNotice.show({
                    //    systitle: "温馨提示", systext: "上传失败!",
                    //});
                }
            }
        }

    };
    $("#Excelform").ajaxForm(options).submit();
}

上面的例子中:<button type="button" οnclick="btnClick();">导入</button></div>

button的type是button,这是如果要提交表单就要写: $("#Excelform").ajaxForm(options).submit();

如果button的type是submit,则不需要写submit()。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值