PDA

View Full Version : Abort Ext.Ajax request AND abort success or failure callback



netsuo
18 Jun 2010, 1:45 AM
Hi,

I'm searching a way that will let me abort any Ext.Ajax success or failure callback from the same function.

Let me explain: I have multiples Ajax request anywhere on my application, now the project move into a multiuser one, so I have to do a user management system, I have to force user to log into the system.

I've done something like this:



Ext.Ajax.on('requestcomplete', function(response)
{
var logged_in = CheckLoginStatus(response);
}
);


It works like this:
1. user is making a regular action in my application
2. the PHP backend intercept the request before actually making it, finds that the user's not logged in anymore
3. operation in the backend is aborted
4. PHP returns an error that user needs to login
5. my function above intercepts that error and fires a new Ext window that tell user it must login again.

All is working great till here.
Now, after the login panel has been shown, the request's callbacks (success or failure) are still fired, and I don't want that.

And I just do not want to have to test every ajax callback, I want to find a way to fire some functions right after "CheckLoginStatus" that will abort any callback after that.

Any thoughts about this ?

Thanks

Stephane

Condor
18 Jun 2010, 2:48 AM
It's a bit tricky, but the following works:

Ext.Ajax.on('requestcomplete', function(response, options){
var logged_in = CheckLoginStatus(response);
if (!logged_in) {
delete options.success;
delete options.failure;
delete options.callback;
// other stuff
}
});

netsuo
18 Jun 2010, 3:51 AM
Thanks a lot !

That did do the trick and saved me a LOT of code !

andersonjf
31 Aug 2015, 3:08 PM
I know this is from a very long time ago, but thank you very much. This little trick is still extremely effective and saved me literally hundreds of lines of code spread across dozens of various view controllers. Thanks!