AJAX works by allowing the browser to communicate with the server in the background.
Instead of reloading the full page, AJAX sends a request silently and waits for the response.
The XMLHttpRequest object is responsible for sending requests and receiving responses from the server.
This object creates the connection between the browser and the server.
The open method defines the request type, the server file, and whether the request is asynchronous.
Using true means the request will run in the background.
After sending the request, the browser does not stop working.
The user can continue interacting with the page while the server processes the request.
When the server sends the response, JavaScript receives it and processes the returned data.
Only the required part of the page is updated.
This complete process happens without refreshing the browser.
This background communication is what makes AJAX fast and efficient.
Understanding this flow is very important because the same logic is used in all AJAX methods including Fetch API and backend communication.