Before AJAX, users would have to manually refresh their mailboxes to check. if they had any new emails. This would MEAN re-loading all of the HTML and CSS, which proved to be slow and ineffcient. Eventually the
XMLHttpRequest API was made so that data could be passed between the server and the browser without having to reload the webpage.
Now, whenever we open our inbox in our browser, we don’t have to reload the page to check if we have a new email, AJAX gets the data from the server and passes it to our browser without having to reload the webpage, which is super helpful and efficient.
Using an Thermostat project as another example, whenever we update the location displayed by the weather API, (using jQuery’s
‘$.get())’ method), data is being passed between the browser and the server, using the
XMLHttpRequest API, without having to refresh the webpage.
Another great example is Google. Ever notice that whenever you start typing to search something, Google somehow auto-predicts what you’re searching for. That’s AJAX in action. The webpage isn’t being reloaded, instead a GET request is being fired off to the server over at Google, and the browser is receiving a JSON object, which contains all of the possible search results. This is then parsed and inserted into the bar, a lot is happening behind the scenes and it’s happening quite quickly.