【问题标题】:EXTJS Ajax request and Content-Disposition attachmentEXTJS Ajax 请求和 Content-Disposition 附件
【发布时间】:2011-03-09 14:24:59
【问题描述】:

我想在加载链接时在 extjs 中获取 watingmessage。响应是一个二进制代码,我想下载它。该链接例如是“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');
      }

我也在 test.php 中尝试过。

       <?php
          header('Content-Disposition: attachment; filename="'.$filename.'"');
          echo $content;
       ?>

但它不起作用。如果我只是加载链接它可以工作,但没有等待消息。

【问题讨论】:

  • 可能是太快了?并且没有延迟显示“等待”消息?
  • 不显示等待消息,但不显示附件。我刚刚得到响应(二进制代码)。也许extjs中有一个函数,我可以说像附件(二进制代码,文件名);
  • “加载链接”是什么意思?您想在文件下载时收到加载消息吗?
  • 不,我只是想在加载链接时收到一条 watingmessage。加载链接需要几秒钟来构建二进制代码。那时我需要一条等待消息。之后我只想要典型的保存对话框来保存文件。

标签: php ajax extjs attachment content-disposition


【解决方案1】:

ExtJS Documentation 中有一个名为LoadMask 的类,旨在显示加载“微调器”以及一条短消息。在您的情况下,您可以这样使用它:

function loadurl(link){
    var mask = Ext.LoadMask(Ext.getBody(), {msg:"Loading..."})
    mask.show();
    Ext.Ajax.request({
        url: link,
        callback: function(options, success, response){
            if (success) {
                // response : my attachment
            }
            else {

            }
            //do whatever work we need to do, then hide the mask
            mask.hide()
        },
    scope: this
});

但是,如果由于某种原因,回调几乎立即返回,则掩码可能不可见,因为您的文件加载速度过快。如果这是一个问题,您可以通过将 Ajax 请求放入 setTimeout 来强制延迟。

【讨论】:

    猜你喜欢
    • 2011-11-19
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2010-11-26
    相关资源
    最近更新 更多