ExtJS AJAX save as dialog box

2019-07-08 20:54发布

I make an ExtJS AJAX request and I want the standard browser 'save as' dialog box to be displayed to the user. The file to download can be a pdf, jpg or png file.

At the moment the AJAX request is successfully submitted but as it's asynchronous no dialog box comes up.

I could simply not use AJAX but there is a lot of javascript code that I need to use prior to making the request and I don't really feel rewriting it to java.

My code looks like this:

var params = getPrintInfo(form);

Ext.Ajax.request({
    url : 'print',
    method : 'POST',
    params : {
      customData: params.customData,
      dpi: params.dpi,
      format: params.format,
      grid: params.grid,
      title: params.title
    },
autoAbort : false,
    success : function(result, request) {
      if(result.responseText==''){
        //display error message
      }else{
        // display save as dialog box
      }
    }
});

In my controller I'm setting the headers to be:

httpResponse.setHeader("Content-disposition", "attachment; filename=" +  this.config.getString("print.file.name")+outputType);

EDIT:

Have actually found this solution:

Ext.DomHelper.append(document.body, {
    tag: 'iframe',
    frameBorder: 0,
    width: 0,
    height: 0,
    css: 'display:none;visibility:hidden;height:1px;',
    src: 'http://blabla.com/f75e927b-2041-473e-86ba-cbbc60dbc285.pdf'
});

Now the question is: How can I change the pdf name to be pretier, for example map.pdf instead of having that long ugly alphanumeric string?

1条回答
Luminary・发光体
2楼-- · 2019-07-08 21:40

You can use window.open to have save as dialog box, for example

window.open('print?parameters...','_blank');
查看更多
登录 后发表回答