tags:

views:

504

answers:

2

is it possible to use the ajaxComplete or ajaxStop features of jQuery to decide whether or not the callback gets called?

Essentially I want to be able to take basic error checking code that is currently in most of my callbacks, and add it to a sort of global callback.

+1  A: 

Sort answer: No.

Long answer: Both ajaxComplete and ajaxStop are jQuery AJAX events. You cannot prevent events from happening - and "event" means nothing else as "execute every callback function that has been registered". Callbacks get called regardless, if you want or not.

What you can do is program your callback so that it does nothing when certain requirements are (or are not) met. In effect this is exactly what you asked for. If you edit your question to explain what you're up to exactly, people can show you how to do it.

Tomalak
A: 

I also wanted to be able to disable the callback event. Sometimes you want to be able to get the server to redirect you to a different action. Currently, this is not possible with a jQuery ajax call because the response has to go back to the calling view.

Samir