2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by hielo
0

When a function executes Synchronously, the following statement is NOT executed until the previous one is done executing - ex:

/* here, the statements are executed one after the other. In other words, if the web server is experiencing delays and it takes 5 seconds to respond then you will see the second alert 5 seconds after the message "Checking Username".
*/
alert("Checking Username");
var username = makeSJAXCall();
alert(username);

By contrast, Asynchronous calls do NOT wait for completion before moving on to the next statement - ex:

/*
here you see the "Checking Username" message and almost immediately after that you will see the second alert. Since the Asynchronous function has not completed, username does not have a value and you should see undefined as the second message.

So how do you "campture/receive" the result. This is where the callback function comes into place, which is what is typically executed onreadystatechange.
*/
alert("Checking Username");
var username = makeAJAXCall();
alert(useranme);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.