Reputation: 1285
I am trying to create a custom function that would be called every time the server sends a response. I can successfully do this in Extjs3 using the following code:
Ext.override(Ext.data.Connection, {
handleResponse : function( response ) {
console.log('function call');
}
});
I would like to know what would I need to change in order for this code to work in Extjs 4.2.0?
Thanks, Y_Y
Upvotes: 3
Views: 1453
Reputation: 1285
Looking inside Extjs 4.2.0 library file Connection.js I noticed there was no 'handleResponse' function declared as in Extjs 3.2.1 was declared. Instead, Extjs 4.2.0 has a 'onComplete' function. Overriding this function gave me the ability to handle few things before 'requestcomplete' similar to overriding 'handleResponse'.
Upvotes: 2
Reputation: 6995
You don't actually need to override or extend anything. The documentation for Ext.data.Connection
shows that it fires three events. Two of them are requestcomplete
which fires when a request succeeds, and requestexception
which fires when a request fails.
Now, refer to the documentation for Ext.util.Observable.observe
which demonstrates how to capture all the events for a given class. Example:
Ext.util.Observable.observe(Ext.data.Connection, {
requestcomplete: function(conn, response, options){
// Do stuff on success
},
requestexception: function(conn, response, options){
// Do stuff on failure
}
});
That's how you get all completion events for all Ext.Ajax
requests. Internally, the observe
method uses the capture
method so you'll have to call releaseCapture
on your class when cleaning up.
Upvotes: 4