PDA

View Full Version : handle/Listen any ajax response globally



sivaciva
22 Feb 2015, 10:49 PM
Hi,

How to handle/Listen any ajax response from server globally in application

If handled globally where to write for e.g in( Application.js or something like that)

Since i am newbie it would be great if you provide any samples

Thanks in advance.

joel.watson
28 Feb 2015, 9:58 AM
Hi,

How to handle/Listen any ajax response from server globally in application

If handled globally where to write for e.g in( Application.js or something like that)

Since i am newbie it would be great if you provide any samples

Thanks in advance.

Check out the events for Ext.Ajax:

http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.Ajax

You could add listeners for any of these events.

Thanks!
Joel

sivaciva
2 Mar 2015, 12:52 AM
thanks for your reply joel.


So i want to handle the exception and it should be written once not by writing exception each time ajax request made,i need to write a common code where any single request made from my application should listen the exception if it is needed


Thanks in advance

joel.watson
2 Mar 2015, 2:37 PM
thanks for your reply joel.


So i want to handle the exception and it should be written once not by writing exception each time ajax request made,i need to write a common code where any single request made from my application should listen the exception if it is needed


Thanks in advance

Hi--

Yes, that's what I'm suggesting. Ext.Ajax is a singleton, so the listeners that you add to the class will be used when this class is used through the application, whether you're calling request() manually, or whether it happens via store's proxy.

I've put together a Fiddle demonstrating this, below (see the console for all the captured failures).

Thanks!
Joel

j1h