I need to call execute ajax call from withing ajaxComplete function. How do I do this without getting stuck in endless loop of ajax calls? Can I unbind ajaxComplete, run ajax call, and then re-bind it? If so, how?
-
Why do you need to do this? If something is hard or seems impossible with a framework, that often means that you're doing it the wrong way.noah– noah2010-01-13 19:48:03 +00:00Commented Jan 13, 2010 at 19:48
-
Actually, it was not that hard, I just checked the settings.url to see what is the target and simple switch did the trick.epitka– epitka2010-01-14 00:42:58 +00:00Commented Jan 14, 2010 at 0:42
Add a comment
|
2 Answers
How about:
function onComplete(event, XMLHttpRequest, ajaxOptions)
{
// Your second AJAX call
$.ajax({
url: "anotherPlace.html",
cache: false
});
}
// Your first ajax call
$.ajax({
url: "test.html",
cache: false,
complete: onSuccess
});
2 Comments
epitka
It has to be from global ajaxComplete(). For now I am just looking at settings.url and if it is the second call just return.
Januz
Well, in that case yeah, you can bind() and unbind() ajax events: docs.jquery.com/Ajax_Events Though the way you're doing it now will probably run faster.