user370306
user370306

Reputation:

AJAX sync and async difference

What's the difference between sync and async AJAX calls.When to use sync and when async?

Upvotes: 8

Views: 21989

Answers (2)

Phillip Schmidt
Phillip Schmidt

Reputation: 8818

Async requests occur on a background thread, meaning that the UI is not going to be blocked while the request is processing (there are a lot of exceptions to this when you get into states and I/O, etc.)

Lets say we have a 10 second web service call that needs to be made. If you call it synchronously, you're not going to be able to navigate to other pages, interact with the web page, etc. If you do it async, you will.

Upvotes: 4

John Parker
John Parker

Reputation: 54445

At a very basic level, you use an asynchronous mode when you want the call to occur in the background and a synchronous mode when you want your code to wait until the call has completed.

The asynchronous mode is the usual approach for AJAX calls, as you generally attach a callback function to the onreadystatechange event so that you can respond when the server-side data is ready, rather than waiting for the data to arrive.

Upvotes: 13

Related Questions