How are AJAX requests made asynchronous if Javascript is not multi-threaded?
Is the implementation browser specific?
So yes, it uses additional threads internally.
In the context of programming, Parallelism is the utilization of multiple threads in an operating system. Routines are able to run at the same time regardless of execution order. JavaScript, however, is single threaded and only one line of code can be executed at any given time.
Ajax is a programming concept. Below are some ways to make Ajax call in JavaScript. Approach 1: In this approach, we will use the XMLHttpRequest object to make Ajax call. The XMLHttpRequest() method which create XMLHttpRequest object which is used to make request with server.
Javascript is a single threaded language. This means it has one call stack and one memory heap. As expected, it executes code in order and must finish executing a piece code before moving onto the next.
The browser execution model is based on the concept of an "event loop". There's only one thread servicing events (slight oversimplification). When an event happens, handlers are called in sequence.
Ajax is just a mechanism that causes certain events. Setting up an HTTP request is synchronous, but just setting it up. The browser responds to the network communications representing the return data from the server by triggering events when that happens.
Modern browsers are somewhat more complicated in that each window may have its own process (or some other system-level "thread" construct, to be general). Also, the new "web worker" feature allows separate thread-like compartments to run concurrently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With