I am binding different loading messages for two different events.
Here are the functions that I'm using to bind the behaviour before AJAX calls. I am calling each function before each matching Ajax submission so that it will show the correct loading messages for each one:
function BindPersonalityLoader()
{
// Bind the loader to personality
$('document').bind("ajaxStart", function() {
// Show the loader
$('img#personality_loader').show();
});
// Bind the loader to personality
$('document').bind("ajaxStop", function() {
// Show the loader
$('img#personality_loader').hide();
});
}
function BindLoadEditPersonalityLoader()
{
// Bind the loader for editing a personality
$('document').bind("ajaxStart", function() {
// Hide the edit form
$('div#quiz_maker_add_personality_wrapper').hide();
// Show the loader
$('div#quiz_maker_edit_personality_loader').show();
});
// Bind the loader for editing a personality
$('document').bind("ajaxStop", function() {
// Hide the loader
$('div#quiz_maker_edit_personality_loader').hide();
});
}
As soon as I have called BindLoadEditPersonalityLoader()
, this becomes permanent for some reason, even if I then call BindPersonalityLoader()
within my code, I expect the other behaviour.
For some reason why I call the code, it is not overriding the "bind".
For example if I run the following code, the behaviour of BindLoadEditPersonalityLoader()
remains throughout, because it was called first:
// Bind the loaders once
BindLoadEditPersonalityLoader();
// Bind the loaders to different behaviour
BindPersonalityLoader();
I have included the two alert()
messages so that I can see when they have been called.
I have tried calling unbind("ajaxStart ajaxStop");
but this didn't work either.
This is how I am calling the binds within my two different events:
// Add a new personality to the quiz
$('form#personality_editor').submit(function(e) {
e.preventDefault();
// Bind the loader to personality loader
BindPersonalityLoader();
// AJAX Call here
});
// Edit a personality already existing within the quiz
$('a.personality_edit').live('click', function(e) {
e.preventDefault();
// Bind loader for editing personality
BindLoadEditPersonalityLoader();
// Ajax call here
});