What is AJAX?
AJAX stands for Asynchronous JavaScript And XML and it works in the following way:
Whenever an event occurs on a web page, eg.: a user clicks a button, an XHR request is created by JavaScript that is sent to the server. The server processes the request and returns a response to the web page which is then processed by JavaScript and the necessary actions are taken, eg.: updating the page content.
In short terms, it is a combination of using built-in browser APIs for fetching data (such as the fetch
API) and DOM manipulation techniques in JavaScript to load content.
Note that while the name implies it works with XML, this is often not the case. Instead, the data is transferred as either plain text or more commonly JSON.
The pros of using AJAX include things like:
- Updating a web page without actually reloading it
- Request and receive data from the server after the page has been loaded
- Send data to the server in the background
On the other hand, there are also disadvantages, such as:
- It wonβt work in case JavaScript is disabled
- If history is not taken care of, it can make the browserβs back button useless
- Since it increases code size, it can make your site vulnerable to security threats
Resources:
Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies: