hi I want to ask about AJAX ,either AJAX makes Synchronous or Asynchronous calls to the Server.As from its name It is ASYNCHRONOUS JS & XML ,but when it comes to sending request to server,it is synchronous or Asynchronous?Help will be Appreciated
Share
I think it would help you if you had a definition of what synchronous and asynchronous mean in this context.
A synchronous call blocks the execution of the Javascript thread that executed it. This means if you have the following code:
You will not see the
Aftermessage until the request has completed and the server has returned data.An asynchronous call does not block the execution of the Javascript thread that executed it. This means that, for the same code block above, the
Aftermessage fires immediately, and does not wait for the request to finish. Because the execution of the code continues in an asynchronous call, you need to use a callback to handle the result. This is what theonreadystatechange()event/method is for.You can choose which type of call is made, synchronous or asynchronous, when you call the
open()method of theXmlHttpRequestobject. By passingtrueto the third argument, the request is asynchronous, if you passfalseit is synchronous.