Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is AJAX called asynchronous?

Why is AJAX called asynchronous? How does it accomplish communication asynchronously with the server?

like image 415
Bhavesh Avatar asked Oct 28 '11 17:10

Bhavesh


2 Answers

It's asynchronous in that it doesn't lock up the browser. If you fire an Ajax request, the user can still work while the request is waiting for a response. When the server returns the response, a callback runs to handle it.

You can make the XMLHttpRequest synchronous if you want, and if you do, the browser locks up while the request is outstanding (so most of the time this is inappropriate)

like image 88
hvgotcodes Avatar answered Nov 14 '22 22:11

hvgotcodes


It's asynchronous because the client and the server run independently of each other for the duration of the function call.

During a normal function call, you make the call, and the calling function doesn't get to execute again until the function call finishes and returns. The caller and the callee are always synchronized.

During an asynchronous function call, you make the call, and then control returns immediately to the caller. The callee then returns a value some indeterminate amount of time later. That "indeterminate amount of time" means the caller and callee are no longer synchronized, so it's asynchronous.

like image 22
Jerry Coffin Avatar answered Nov 14 '22 20:11

Jerry Coffin