HTML表单返回并下载文件时显示进度掩码

Show progress mask when HTML form post back and downloads file

本文关键字:显示 掩码 文件 表单 返回 下载 HTML      更新时间:2023-09-26

我是javascript和HTML的新手。当我的html表单被张贴并下载文件时,我正在努力显示繁忙的图像。我正在使用http://malsup.com/jquery/form/#options-对象插件。我正在使用IE 9。我寄回了一张表格,作为回报,我收到了一份文件。

当我发帖时,我看到繁忙的掩码,然后IE要求我保存为文件,但掩码不会消失。没有调用成功/错误回调。下面是我的代码快照。

非常感谢您为解决此问题提供的指导。

`frmExport.html
<head>
<script src="js/jquery-1.8.0.js"></script>
<script src="js/jquery.form.js"></script>
<script src="js/frmExport.js"></script>
</head>
<body onload="......">
<form id="frmExport" onsubmit="return exportFile();" enctype="multipart/form-data" method="post">
<fieldset>
<legend class="cuesGroupBoxTitle">Export File</legend>
    <table border="0" cellpadding="0" cellspacing="8">
        <tr>
        <td width="50%">Export File:</td>
        <td><input type="submit" id="ExportFileButton" value="Export" /></td>
        </tr>
    </table>
</fieldset>
</form>
</body>
frmExport.js
function exportSuccess(responseText, statusText, xhr, $form)
{ 
hideMask("exportFile");
alert(statusText");
}
function exportError()
{
hideMask("exportFile");
alert("An error occurred while exporting file.");
}
function exportFile() 
{
if(confirm("Exporting file may take sometime. Do you want to continue?"))
{
    var options = 
    { 
        type:          "POST",
        success:       exportSuccess,  // post-submit callback 
        error:         exportError,
        url:           'exportURI',
        dataType:      'text'
    }; 
    // bind to the form's submit event 
    $('#frmExport').submit(function() 
    { 
        $(this).ajaxSubmit(options); 
        showMask("exportFile");
        //always return false
        return false; 
    });
}
}`

我敢肯定,您的问题是在提交已经触发时挂接提交事件($('#frmExport').submit(...))。试着把它挂在文档上。准备好。

$(document).ready(function() {
var options = 
{ 
    type:          "POST",
    success:       exportSuccess,  // post-submit callback 
    error:         exportError,
    url:           'exportURI',
    dataType:      'text'
}; 
// bind to the form's submit event 
$('#frmExport').submit(function() 
{ 
    $(this).ajaxSubmit(options); 
    showMask("exportFile");
    //always return false
    return false; 
});
});