41

What does Asynchronous means in Ajax? and also how does Ajax know when to pull data without server polling?

4 Answers 4

54

Asynchronous means that the script will send a request to the server, and continue it's execution without waiting for the reply. As soon as reply is received a browser event is fired, which in turn allows the script to execute associated actions.

Ajax knows when to pull data from server, because you tell it when to do it.

3
  • 1
    "Ajax knows when to pull data from server, because you tell it when to do it." How do i do that?
    – JCX
    Commented Aug 3, 2010 at 5:25
  • 6
    You, as a creator of the script, tell it to send a request to server when certain conditions are met (for example: 'when DOM is ready', 'when user presses this button', 'when value in textfield changes', 'every 5s', etc).
    – Mchl
    Commented Aug 3, 2010 at 5:34
  • 3
    Err... on the internet? Search for 'AJAX tutorials' w3schools.com/ajax/ajax_intro.asp
    – Mchl
    Commented Aug 3, 2010 at 5:57
6

Just about what it means in any other context. When you make an ajax call, it doesn't block until it returns.

3

Browsers do not give access to threading model, so we have just a single thread to handle the User Interface. So, all the modifications in the application is in the same thread.

Fortunately, the browsers exposes several async API's, like XHR(XMLHttpRequest), also known as AJAX. When you register a event handler for some object, the action for this object will be executed in another thread and the browser will trigger the event in the main thread.

So async mean that the browser won't wait for when the main thread is free to perform the action

0

Asynchronous (in Ajax) processes incoming requests in a constant event stack and sends small requests one after the other without waiting for responses. In other words, asynchronous ajax call allow the next line of code to execute, whereas synchronous call stop JavaScript execution until the response from server.

Not the answer you're looking for? Browse other questions tagged or ask your own question.