EXTJS Ajax 请求和 Content-Disposition 附件
我想在加载链接时在 extjs 中获得一条等待消息。响应是一个二进制代码,我想下载它。该链接例如是“test.php”。
function loadurl(link){
Ext.MessageBox.wait('Loading ...');
Ext.Ajax.request({
url: link,
callback: function(options, success, response){
Ext.MessageBox.updateProgress(1);
Ext.MessageBox.hide();
if (success) {
// response : my attachment
}
else {
}
},
scope: this
});
我也在test.php
{
...
//functioncall
loadurl('test.php');
}
中尝试过。
<?php
header('Content-Disposition: attachment; filename="'.$filename.'"');
echo $content;
?>
但这不起作用。如果我只是加载链接,它就可以工作,但无需等待消息。
I want to get a watingmessage in extjs while loading a link. The response is a binarycode, which I want to downlad. The link is for example "test.php".
function loadurl(link){
Ext.MessageBox.wait('Loading ...');
Ext.Ajax.request({
url: link,
callback: function(options, success, response){
Ext.MessageBox.updateProgress(1);
Ext.MessageBox.hide();
if (success) {
// response : my attachment
}
else {
}
},
scope: this
});
}
{
...
//functioncall
loadurl('test.php');
}
I also tried in test.php.
<?php
header('Content-Disposition: attachment; filename="'.$filename.'"');
echo $content;
?>
But it doesnt work. If I just load the link it works, but without waiting message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ExtJS 文档 中有一个名为
的类LoadMask
旨在显示正在加载的“旋转器”以及一条短消息。在您的情况下,您将像这样使用它:但是,如果出于某种原因,回调几乎立即返回,则掩码可能不可见,因为您的文件加载太快。如果这是一个问题,您可以通过将 Ajax 请求放入
setTimeout
中来强制延迟。In the ExtJS Documentation there is a class called
LoadMask
which is designed to show a loading 'spinner' along with a short message. In your case, you would use it like this:However, if, for whatever reason, the callback comes back almost immediately, then it is possible that the mask will not be visible because your file loaded too fast. If this is an issue, you could force a delay by putting your Ajax request inside a
setTimeout
.