Asynchronous JavaScript and XML (AJAX)

AJAX stands for Asynchronous JavaScript and XML. It is a buzzword and technique in web-development that uses JavaScript to get data from an external XML document, or more commonly, data from a database that has been formatted as XML via a server side scripting language such as PHP. First a network request to the server is created using JavaScript, when the request is finished, the program updates the current web page based on the results of that request without refreshing the page.

In non AJAX web applications, a user presses a button or clicks a link which calls a server to create HTML that is sent to the browser and is rendered in the form of a new web page – think Wikipedia.

Using AJAX, a user presses a button, and an XMLHttpRequest JavaScript request object is created. It calls the server with a, GET, POST, PATCH, or DELETE HTTP request. Once the request is returned, the JavaScript program makes the necessary updates to the current page – think Facebook chat.

AJAX is often referred to as XHR, which stands for XMLHttpRequest. XHR is a core JavaScript API that most browsers implement. XHR is often used to retrieve data formatted into JSON objects or even transfer plain text, instead of XML. This is because XML is verbose and larger packets mean slower network calls.

Here is a simple example:

var xhr = new XMLHttpRequest();
xhr.open('GET', "http://infosnacks.com/", false);
xhr.send();