AJAX Intro

AJAX means Asynchronous JavaScript XML.

AJAX is a way to update data in a web page without recharging.

AJAX allows modification of a part of our website without leaving the page.

AJAX is a way to exchange data between our website and an internal or external Web service.

AJAX uses XML as a data interchange format.

HttpRequest uses AJAX for asynchronous requests with any web service.

example AJAX

If we have the following web service that returns a text message.

File "info.txt"

<p>Website that simulates the information offered by a web service</p>

To collect this information from our website "ajax.htm" use AJAX and show the information of the previous file "info.txt".

File "ajax.htm"

<!DOCTYPE html> <html> <head> <script> function loadInfo() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","info.txt",true); xmlhttp.send(); } </script> </head> <body> <h2>Let AJAX get more information</h2> <div id="myDiv"></div> <button type="button" onclick="loadInfo()">Get Info</button> </body> </html>