event handling - Synchronization in JavaScript -


I have such an experiment case:

When a user clicks on a radio button, then I Call to get some information depending on the AJAX user selection, when the user clicks on a link, then I use the AJAX call information form to display a warning.

I need this:

  1. To make sure the result of AJAX calls is correct
  2. If user to open alert, before I want to display the waiting icon, or else display the warning
  3. If any response 2s do not come from AJX, I will display a warning in any way
  4. < / Ol>

    I'm really asking that How the case of this specific use in S, because I understand that the timer is how to combine, jQuery and Ajax callbacks, and so on.

    I see the problem in a more general way:

    We have three incidents (AJX's success, user click, timeout) and to get some triggers from some conditions Do you want to associate the code on events that have a structure that allows you to combine actions with a combination of events?

    Am I using the wrong approach only?

1 - If order of feedback is important, then it is not useful to allow many parallel requests , Which means that when the user selects a radio button, you should queue the operation. Getting along with the promise is very easy.

For example.

  var promo queue; Function Process Request (radio value) {return $. AJAX ({...}) done (/ * handle request * /); } Function onRadioClicked () {var radiovalue = this.value; // It is assuming that this is your radio element / if the queue was initialized, then our next action queue using "Next", // otherwise directly process the request and the quote // Returned promises Start with the promise queue = promiseQueue? Promise QEI Then (Process Requests. Bind (empty, radio value)): Process request (radio value); }  

2 - Do not use alerts as it will block your UI. You can use jQuery UI plugin or something similar. Every time the reaction is reacted, you can check to see if other requests have been processed or they have all been processed.

3 - You timeout code> $ Allow maximum time to complete AJAX . Take a look at


Comments