AJAX

Ajax, (also AJAX /ˈeɪdʒæks/; short for "Asynchronous JavaScript and XML" or "Asynchronous JavaScript transfer (x-fer)") , is a set of web development techniques that uses various web technologies on the client-side to create asynchronous web applications. With AJAX, web applications can send and retrieve data from a server asynchronously without interfering with the display and behaviour of the existing page. It is a mix of XML and JavaScript, and has the same file extension as JavaScript (.js). It was first appeared in March 1999.
==History==
In the early-to-mid 1990s, most websites were based on complete HTML pages. Each user action required a complete new page to be loaded from the server. This process was inefficient, as reflected by the user experience, which are that all page content disappeared, then the new page appeared. Each time the browser reloaded a page because of a partial change, all the content had to be re-sent, even though only some of the information had changed. This placed additional load on the server and made bandwidth a limiting factor in performance.
Since 1996, most functionalities are developed with AJAX for multiple websites and web browsers, such as the iframetag, which was introduced by Internet Explorer in 1996. In 1998, the Microsoft Outlook Web Access team developed the concept behind the XMLHttpRequest scripting object.https://web.archive.org/web/20070623125327/http://www.alexhopmann.com/xmlhttp.htm It appeared as XMLHTTP in the second version of the MSXML library, which shipped with Internet Explorer 5.0 in March 1999.https://web.archive.org/web/20100306164701/http://blogs.msdn.com/ie/archive/2006/01/23/516393.aspx
The functionality of the Windows XMLHTTP ActiveX control in IE 5 was later implemented by Mozilla Firefox, Safari, Opera, Google Chrome, and other browsers as the XMLHttpRequest JavaScript object.
==Technologies==
The term Ajax has come to represent a broad group of Web technologies that can be used to implement a Web application that communicates with a server in the background, without interfering with the current state of the page. In the article that coined the term Ajax,"Ajax: A New Approach to Web Applications" (September 10th, 2015, Archived)ISBN 978-0-470-10675-4. (July 5, 2008, Archived) Jesse James Garrett explained that the following technologies are incorporated:
*HTML (or XHTML) and CSS for presentation
*The Document Object Model (DOM) for dynamic display of and interaction with data
*JSON or XML for the interchange of data, and XSLT for XML manipulation
*The XMLHttpRequest object for asynchronous communication
*JavaScript to bring these technologies together
==Examples==
===JavaScript example===
An example of a simple Ajax request using the GET method, written in JavaScript.
get-ajax-data.js:
// This is the client-side script.
// Initialize the HTTP request.
let xhr = new XMLHttpRequest();
// define the request
xhr.open('GET', 'send-ajax-data.php');
// Track the state changes of the request.
xhr.onreadystatechange = function () {
	const DONE = 4; // readyState 4 means the request is done.
	const OK = 200; // status 200 is a successful return.
	if (xhr.readyState === DONE) {
		if (xhr.status === OK) {
			console.log(xhr.responseText); // 'This is the output.'
		} else {
			console.log('Error: ' + xhr.status); // An error occurred during the request.
		}
	}
};
// Send the request to send-ajax-data.php
xhr.send(null);
send-ajax-data.php:
<?php
// This is the server-side script.
// Set the content type.
header('Content-Type: text/plain');
// Send the data back.
echo "This is the output.";
?>
===Fetch example===
fetch('send-ajax-data.php')
 .then(data => console.log(data))
 .catch (error => console.log('Error:' + error));
===ES7 async/await example===
async function doAjax1() {
 try {
 const res = await fetch('send-ajax-data.php');
 const data = await res.text();
 console.log(data);
 } catch (error) {
 console.log('Error:' + error);
 }
}
doAjax1();
Fetch relies on JavaScript promises.
*The fetch specification differs from Ajax in the following significant ways:
*The Promise returned from fetch() won't reject on HTTP error status even if the response is an HTTP 404 or 500. Instead, as soon as the server responds with headers, the Promise will resolve normally (with the ok property of the response set to false if the response isn't in the range 200–299), and it will only reject on network failure or if anything prevented the request from completing.
fetch() won't send cross-origin cookies unless you set the credentials init option. (Since April 2018. The spec changed the default credentials policy to same-origin. Firefox changed since 61.0b13.)
==External Links==
*AJAX in Wikipedia.
==References==
Category:Web development