PDA

View Full Version : File Download with AJAX Request



sridhar.boganathan
17 Apr 2012, 5:45 AM
Hi All,

I am trying to download a Excel file from my server side application. I am using AJAX request to do the same with Ext JS. It is not working. It gives me the same kind of response of other AJAX Requests, the file is not downloading. If I try the same with normal html file, able to download. It is working fine with other AJAX Framework also.


//Ext JS AJAX Request
Ext.Ajax.request({
url: 'http://myappurl/ExportData',
params: {
studid: '12343',
years: '2011'
},
method: 'POST',
cors: true,
success: function(response){
console.log("Exported");
},
failure: function(response){
}
});

//Normal HTML
<html>
<head>
<title>
POC
</title>
</head>
<body>
<form action="http://myappurl/Exports" method="POST">
studid:<input type="textbox" name="studid"/><br/>
years:<input type="textbox" name="years"/><br/>
<input type="submit" text="Export"><br/>
</form>
</html>

-Please advice,
Sridhar

scottmartin
17 Apr 2012, 8:51 AM
Is anything happening at all? If you enter the URL manually what happens?
Have you set your content type? 'Content-Type: application/vnd.ms-excel' in your headers?

Scott.

sskow200
17 Apr 2012, 9:33 AM
Ext.create('Ext.Component', {
autoEl: {
tag: 'iframe',
onload: 'customOnLoadFunction', //optional
src: '/path/to/file/download/'
},
renderTo: Ext.getBody()
});

sridhar.boganathan
17 Apr 2012, 10:04 PM
Is anything happening at all? If you enter the URL manually what happens?
Have you set your content type? 'Content-Type: application/vnd.ms-excel' in your headers?

Scott.

Yes, I have compared the two responses from implementation in Ext JS and other implementation. Both are same. Both of them have same content-type 'Content-Type: application/vnd.ms-excel'.

-Sridhar.