1. #1
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    94
    Answers
    1
    Vote Rating
    0
    sridhar.boganathan is on a distinguished road

      0  

    Default Unanswered: File Download with AJAX Request

    Unanswered: File Download with AJAX Request


    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.

    Code:
    //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

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,001
    Answers
    666
    Vote Rating
    456
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    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.

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Answers
    8
    Vote Rating
    3
    sskow200 is on a distinguished road

      0  

    Default you must use an iframe....

    you must use an iframe....


    Code:
    Ext.create('Ext.Component', {
                            autoEl: {
                                tag: 'iframe',
                                onload: 'customOnLoadFunction', //optional
                                src: '/path/to/file/download/'
                            },
                            renderTo: Ext.getBody()
                });

  4. #4
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    94
    Answers
    1
    Vote Rating
    0
    sridhar.boganathan is on a distinguished road

      0  

    Default


    Quote Originally Posted by scottmartin View Post
    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.

Thread Participants: 2