AJAX

Asynchronous JavaScript And XML (AJAX)

Typical AJAX Procedure

  1. A DOM event is fired

  2. An XMLHttpRequest object is created as part of the event handler

  3. The XMLHttpRequest object sends an HTTP request to a server

  4. The server processes the request and sends a response back to the browser

  5. The response is read by JavaScript and the DOM is updated accordingly

The XMLHttpRequest Object

XMLHttpRequest Example

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    var node = document.getElementById("one");
    node.innerHTML = this.responseText;
  }
};
xhttp.open("GET", "file.txt", true);
xhttp.send();

HTTP Requests

The send Methods

The setRequestHeader Method

The onreadystatechange Property

Retrieving the HTTP Response Data

XMLHttpRequest Events

Abstracting XMLHttpRequests