[Interview Question] What are the commonly used techniques in AJAX?

AJAX stands for “Asynchronous JavaScript and XML.

AJAX uses the following techniques:

– JavaScript.
– XML/XSLT and XMLHttpRequest object
– Document Object Model (DOM).
– HTML, Extensible HTML (XHTML) and Cascading Style Sheets (CSS).

How Ajax is working

In details: XML/XSLT and XMLHttpRequest object

XMLHttpRequest object

XMLHttpRequest (XHR) is an API that allows web pages to send and receive XML (or other data) via the HTTP protocol. XMLHttpRequest object is supported by all major browsers including the Internet Explorer 7. Any data may be received by XMLHttpRequest object such as JSON and html content.

The main benefit of the XMLHttpRequest that you can create responsive web applications that do not require re-downloading the entire page to display new data in the entire page or particular section in the page.

You can use the XMLHttpRequest object as following:

if (window.XMLHttpRequest)
{
   var oReq = new XMLHttpRequest();
   if (oReq) {
      oReq.open("GET", "http://localhost/test.xml");
      oReq.send();
      console.log(oReq.statusText);
   }
}

XML/XSLT

XML stands for Extensible Markup Language. It is the markup language that used in to transport and store data over the network where XSLT (stands for Extensible Stylesheet Language Transformations) is the recommended style sheet language for XML. With XSLT you can add and remove,hide and display, edit and rearrange the elements and attributes to or from the xml file.

See the example: Displaying XML with XSLT