Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is AJAX really asynchronous?

When you fire an ajax call, what we typically do in the browser side code is have a "xmlhttp" variable and check for status changes until the response is loaded, which means the client side maintains some sort of connections/thread to the server and the server responds via that connection back to the client. The only difference I see is that the page is not refreshed and that brings me to the very basic question, is ajax really asynchronous?

Compared to JMS where the request is sent and there is absolutely no connection between the Client and Server and the response is sent via different thread initiated by the server. Isn't JMS really asynchronous. I'm confused. Can someone please clarify.

like image 262
spatik Avatar asked Dec 07 '22 01:12

spatik


1 Answers

AJAX is said to be asynchronous in the sense that waiting for requests does not block the page's user interface. In other words: when you send a whatsapp message and you actively wait for the reply, then you are doing a synchronous request: no matter if your wife is asking you for going to bed. You won't go to bed until you get the reply. But if you send the message and you still want to do other things like going to bed with your wife, then you'll do an async request: you will read the message when the phone rings (an AJAX onload event).

The UI thread of a web page would be your wife.

like image 50
Claudix Avatar answered Dec 19 '22 10:12

Claudix