Issue
I want, that a ajax.stop function works only for one time - at the first pageload, after that, I don't need this function. For that I have tried it with this code.
if(init===false)
{
console.log('1) loadpage start');
load_page(<?php echo $page->id;?>);
//Wait till the page is recieved, than go on
$(document).ajaxStop(function() {
console.log('2) load page -> ajaxStopp init:'+init);
setup_elements();
});
init=true;
}
I wondering why the ajaxstop function will work again if I do later another ajaxcall. At this I get the "2)"
message from the console instead I see that the variable "Init" is true.
Maybe I understand the way which ajax.stop
works wrong?
Solution
Register a handler to be called when all Ajax requests have completed. documentation
So what you wish to do probably is this:
$(document).ajaxStop(function() {
if(init===false){
console.log('2) load page -> ajaxStopp init:'+init);
setup_elements();
init=true;
}
});
So you just misplaced your if
condition.
Now ajaxStop()
will still execute every time an ajax resquest has completed... But will do nothing, except on page load.
Answered By - Louys Patrice Bessette Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.