Tutorial: W3Schools Home Next Chapter
Tutorial: W3Schools Home Next Chapter
Tutorial: W3Schools Home Next Chapter
Tutorial
« W3Schools Home Next Chapter »
AJAX = Asynchronous JavaScript and XML.
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
xmlhttp.onreadystatechange=function()
{ document.getElementById("myDiv").innerHTML=xmlhttp.respons
eText; } }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send(); }
AJAX Introduction
« Previous Next Chapter »
HTML / XHTML
CSS
JavaScript / DOM
If you want to study these subjects first, find the tutorials on our Home
page.
What is AJAX?
AJAX = Asynchronous JavaScript and XML.
Classic web pages, (which do not use AJAX) must reload the entire page if
the content should change.
The div section will be used to display information returned from a server.
The button calls a function named loadXMLDoc(), if it is clicked:
<html>
<body>
</body>
</html>
Next, add a <script> tag to the page's head section. The script section
contains the loadXMLDoc() function:
<head>
<script type="text/javascript">
function loadXMLDoc()
{
.... AJAX script goes here ...
}
</script>
</head>
AJAX - Create
an XMLHttpRequest Object
« Previous Next Chapter »
xmlhttp=new XMLHttpRequest();
Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object:
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
To handle all modern browsers, including IE5 and IE6, check if the browser
supports the XMLHttpRequest object. If it does, create an XMLHttpRequest
object, if not, create an ActiveXObject:
Example
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}