AJAX is a technology that allows a website user to interact with the server without reloading the web page. This allows us to turn a web page from a static piece of content into a dynamic web application. It is possible to make a web page interactive with JavaScript alone, but to talk to the server we need AJAX. Usually, the reason we need to talk to the server is to talk to a database, either requesting data or recording changes.
Here’s some examples of typical use cases where AJAX is used in the operation of your website:
Update Cart
. AJAX will send the new quantity to the server which will calculate a new total price. The new price is returned to the user’s web browser and displayed in the cart without the page reloading.Delete
on the relevant page. Without AJAX, you would now wait several seconds while the page is deleted from the database and the whole page is reloaded. You lose control of the screen while this operation is happening. With AJAX, you never lose control of the screen. The page is deleted from the database in the background, and when it is complete AJAX will send back confirmation to the web browser that the deletion was successful. A message is then dynamically displayed on the screen showing the deletion was successful without the page reloading.AJAX stands for Asynchronous JavaScript And XML. To break that acronym down:
XMLHttpRequest
API which is written in the JavaScript scripting language.The XMLHttpRequest
API is a somewhat cumbersome beast to use. Rather than call it directly, most modern web applications use JavaScript libraries with AJAX functionality. These libraries wrap around the low level XMLHttpRequest
API and abstract away the complexity. The most popular JavaScript library for this purpose is jQuery with its $.ajax()
method.
Read more about AJAX at W3 Schools AJAX tutorials and the Wikipedia AJAX article.