1

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?

2
  • 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. Commented 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. Commented Jan 14, 2010 at 0:42

2 Answers 2

0

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
});
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.
0

Can't you just use a global variable. First time run check if variable is set, if not give it a value. Second time you run it, check again and variable is probably set.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.