开发者

AJAX sync and async difference

What's the difference between sync and async AJAX calls.When to开发者_如何学编程 use sync and when async?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜