2

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?

Sfairas
  • 932
  • 4
  • 13
  • 21

1 Answers1

1

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

window.open('print?parameters...','_blank');
e-zinc
  • 4,491
  • 2
  • 20
  • 17
  • This short of does what I want. The only problem is that, for a moment, when my response comes back a new tab opens up and closes instantly which is not really nice. – Sfairas Apr 10 '12 at 15:40