使用 jquery 调用 WebMethods / WebService 是阻塞的
我正在服务器上生成一个文件,这需要一些时间。为此,我有一个隐藏的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定你到底在做什么,但也尝试将 iframe.src=... 代码放入 window.setTimeout 中。
Not sure exactly what you doing, but try putting your iframe.src=... code in window.setTimeout as well.