PDA

View Full Version : Reading the response from the server before it is loaded into a store



israel.galan
9 Jan 2012, 10:52 PM
Hello,
I have a JSON store that gets data from a remote server through a PHP script. Sometimes the script throws errors and therefore the Store fails to load. I would like to control that from the client side but I have not been able to find an event that fires AFTER the response has been received but BEFORE the data is loaded onto the store.
I need such event to access the responseText from the response.

Does anyone know which event I should use?

Thanks in advance

evilight
10 Jan 2012, 1:16 AM
meet the same situation. waiting for answer ~o):D

israel.galan
31 Jan 2012, 8:12 PM
Nobody???
Or is it so obvious that the ExtJS Gods cannot be bothered :-) ?

dedoz
31 Jan 2012, 8:42 PM
u dont even need extjs for this, just use firebug in firefox or developer tools or w/e in chrome

this way u can see the data sent to the server and the data response from the server and there u check if an error in the data sent or data received

or i misunderstood ur question :d maybe u want to send an error msg from the php script and on the client side u recive this msg and do something ? :d

vietits
31 Jan 2012, 9:02 PM
If you use Ajax server proxy, then let try the following code:

Ext.Ajax.on('requestcomplete', function(conn, response, options){
// your code here
});

israel.galan
31 Jan 2012, 10:29 PM
Great, that works fine.
Since I have many different requests in my application, I can't handle all the exceptions in the same way. I have to delegate the handling to the request proxy.

Here is the code:

Ext.Ajax.on('requestcomplete', function(conn, response, options){
try{
eval("(" + response.responseText + ')')
}
catch(e){
var proxy=response.request.options.scope;
proxy.fireEvent('exception');
}
});


After this, I just need to create the 'exception' event listener for the proxies that I want.

Now, I know I shouldn't use eval() to evaluate the validity of my JSON response, but that was the easiest thing to do.

Thanks again