PDA

View Full Version : How to save a reposnse which has a file, using AJAX Post call?



kislay.kishore
11 Jul 2012, 1:41 AM
Hi ,

I am stuck with a tricky situation.

I am sending the SVG data for a chart to server side, using a post Ext.Ajax call. And it sets an image file into response. How do we get this file saved at client's disk and show him "Save As" dialog box.

Previously, I have worked with Document.location.href = "someURL", but this always has to be a GET request...I dont want to use a GET request here as SVG would be very huge for a GET request to handle.

Please suggest.

tvanzoelen
11 Jul 2012, 3:02 AM
You can do that via an iFrame



Ext.Ajax.request(
{
url: url,
params: params,
form: application.downloadForm,
isUpload: true,
success: function(response, options) {

},
failure: function(response, options) {

}
});



application.downloadForm is a reference created once like this



application.downloadFrame = body.createChild({
tag: 'iframe'
, cls: 'x-hidden'
, id: 'iframe'
, name: 'iframe'
});

application.downloadForm = body.createChild({
tag: 'form'
, cls: 'x-hidden'
, id: 'form'
, target: 'iframe'
});


body is Ext.getBody()