2

I show a waiting dialog and then i create an iframe with the url of the file and append it to the document.

 Neptune.ShowWaitingDialog();
     iFrame.src = "ExportReportAllMediaDetailsCsv/?" + $.param(object);
     iFrame.style.display = "none";
     iFrame.onload = function () {
        parent.Neptune.CloseWaitingDialog();
    };
    document.body.appendChild(iFrame);

If there is an error on the server side the iFrame.onload function executes accordingly and the waiting dialog is closed, however if a file is returned the onload function doesnt get executed and the waiting dialog stays open.

my question is, if a file is returned doesnt the iframe get refreshed and hence cause the onload event to execute? if no then is there a way to detect if a file has been returned?

4

1 回答 1

4

我这样做的方式,取自 TJ Crowder 对我的这个老问题的回答,是这样的:

  1. 添加一个名为“nonce”(或任何您想要的)的隐藏表单字段或 GET 参数。在页面创建时或使用 JavaScript 填充唯一的数字或随机字符串。

  2. 在服务器上,查找“nonce”参数并添加一个名为“FILE_READY”(或任何您想要的)的 cookie,并将其值设置为 nonce 值。像往常一样返回文件。

  3. 在客户端上,当表单发布或 iframe “src”被设置时——换句话说,当你启动文件下载时——启动一个 JavaScript 间隔计时器来检查“FILE_READY”cookie 的当前值。每 100 毫秒左右检查一次;它不必非常频繁。

  4. 只要“FILE_READY”cookie 具有在“nonce”参数中发送的值,那么您就知道 HTTP 响应已从服务器返回。

奇迹般有效。

于 2013-04-30T14:03:50.707 回答