使用 jquery 调用 WebMethods / WebService 是阻塞的

发布于 2024-08-28 03:43:28 字数 832 浏览 3 评论 0原文

我正在服务器上生成一个文件,这需要一些时间。为此,我有一个隐藏的 iframe,然后将其 .src 属性设置为一个 aspx 文件,即 iframe.src = "/downloadFile.aspx"

发生这种情况时,我想调用一个 Web 服务返回的进展。为此,我想我可以使用 window.setInterval 或 window.setTimeout 但一旦我设置 iframe src 属性,Javascript 似乎就会被阻止。

有谁知道如何解决这个问题或者尝试不同的方法?

我也尝试过处理程序,但请求永远不会到达服务器,所以我假设是浏览器/javascript 问题。

//获取文件的函数

function GetFile() {
        setTimeout(GetProgress, 1000);

        var iframe = document.createElement("iframe");
        document.body.appendChild(iframe);

        iframe.src = "downloadFile.aspx";
}

/*不起作用 - 获取进度的函数发布数据,但在 iframe 完成并向用户呈现文件下载对话框之前永远不会收到它。 */

function GetProgress() {

        $.post('progress.file', function(data) {

            console.log(data);
            setTimeout(GetProgress, 1000);
        });
    }

I'm generating a file on the server which takes some time. For this, I have a hidden iframe which I then set the .src attribute to an aspx file i.e iframe.src = "/downloadFile.aspx"

While this is taking place, I'd like to have a call to a web service return the progress. To do this, I thought I could use window.setInterval or window.setTimeout but Javascript seems to be blocked as soon as I set the iframe src attribute.

Does anyone know how to get around this or perhaps try a different approach?

I have also tried handlers, but the request never gets to the server so I'm assuming is a browser/javascript issue.

//Function that gets the file

function GetFile() {
        setTimeout(GetProgress, 1000);

        var iframe = document.createElement("iframe");
        document.body.appendChild(iframe);

        iframe.src = "downloadFile.aspx";
}

/*DOES NOT WORK - Function that gets progress posts data but never recieves it until the iframe has finished and presents the file download dialog to the user. */

function GetProgress() {

        $.post('progress.file', function(data) {

            console.log(data);
            setTimeout(GetProgress, 1000);
        });
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倦话 2024-09-04 03:43:28

不确定你到底在做什么,但也尝试将 iframe.src=... 代码放入 window.setTimeout 中。

Not sure exactly what you doing, but try putting your iframe.src=... code in window.setTimeout as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文