views:

2734

answers:

6

Hello,

I'm using ExtJS to make a form that generates a report from the data in the database in CSV format. After the user chooses a simple range of dates to extract the data and submits, running the following code :

var frm = document.createElement('form');
frm.id = 'frmDummy';
frm.name = id;
document.body.appendChild(frm);

Ext.MessageBox.wait('Generating CSV File ...');

Ext.Ajax.request({
    url: 'csv_extract_ajax.php?start_time='+txtDateFieldFrom.getRawValue()+'&end_time='+txtDateFieldTo.getRawValue(),

    method : 'POST',

    form: Ext.fly('frmDummy'),

    isUpload: true, 

    success: function(o, r, n){

        Ext.MessageBox.updateProgress(1);
        Ext.MessageBox.hide();
    },

    failure: function(o, r, n){

        Ext.MessageBox.updateProgress(1);
        Ext.MessageBox.hide();
    },

    callback: function(o, r, n){

        Ext.MessageBox.updateProgress(1);
        Ext.MessageBox.hide();
    },     

    scope: this
});

The associated php file simple outputs a CSV string, working file.

Since the isUpload is true, it seems that the callback is never returned to the user. As soon as I remove it, the callback is called but the file is not uploaded to the client.

The problem now, everything is working perfectly but the MessageBox never disappears since the callbacks are never called (success, failure or callback)

Any idea ? :P

Additional info:

PHP header :

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: private");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Accept-Ranges: bytes");
A: 

Do you noticed this in every browser, or just in a particular browser?

Firefox 3.5 (with Firebug installed) appears to have a bug that means that readystatechange does not get updated which would mean that callbacks do not get invoked.

wrumsby
I've tried with Chrome, same thing, so that's not it. Thanks anyway :)
Amadeus45
+1  A: 

Try changing:

l: 'csv_extract_ajax.php?start_time='+txtDateFieldFrom.getRawValue()+'&end_time='+txtDateFieldTo.getRawValue(),

to

l: 'csv_extract_ajax.php?'+ Ext.urlEncode({ start_time: txtDateFieldFrom.getRawValue(), end_time: txtDateFieldTo.getRawValue() }),

Nothing wrong with the PHP, the isUpload seems to kill the callback. I've tried but same thing. Thanks anyway :)
Amadeus45
See http://extjs.com/forum/showthread.php?t=56864
That doesn't cut it, but thanks for your help. +1
Amadeus45
+1  A: 

Is there any error displayed in the page?

What is the content type of response? The extjs api doc says it should be set to "text/html".

If it still not working you can try to put a breakpoint in doFormUpload(). This method is present in connection.js. Inside this you can find a inner method called cb(), this method will be called once the server returns. You can start debugging from there.

all the best.

Arun P Johny
No error... I'll continue to investigate, thanks for the help. +1
Amadeus45
+1  A: 

As soon as I remove it, the callback is called but the file is not uploaded to the client.

Setting isUpload to true means you are gonna to upload file from client to server, but this is not your case, I'm afraid.

Thevs
A: 

If you don't have a file to upload, why are you setting isUpload to true?

Also, if you are posting a data to a PHP script and if that script returns a CSV string, why are you trying to send it as attachment? Why not send it as regular response text?

SolutionYogi
+2  A: 

This is an excerpt from Ext.Ajax.request documentation:

isUpload : Boolean (Optional) True if the form object is a file upload (will usually be automatically detected). File uploads are not performed using normal "Ajax" techniques, that is they are not performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the DOM element temporarily modified to have its target set to refer to a dynamically generated, hidden which is inserted into the document but removed after the return data has been gathered. The server response is parsed by the browser to create the document for the IFRAME. If the server is using JSON to send the return object, then the Content-Type header must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body. The response text is retrieved from the document, and a fake XMLHttpRequest object is created containing a responseText property in order to conform to the requirements of event handlers and callbacks. Be aware that file upload packets are sent with the content type multipart/form and some server technologies (notably JEE) may require some custom processing in order to retrieve parameter names and parameter values from the packet content.

As you can see, upload request is returned via IFRAME and only emulates standard AJAX response, so that callbacks are not called.

Thevs