Hello all,
I am just learning AJAX because I find it interesting but my first example does not work the way I planned it.
Here is the code:
This is my HTML file named ajax.html
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="" />
<title>Untitled 3</title>
<script type="text/javascript" language="javascript" src="jscript.js">
</script>
</head>
<body>
<h1> My AJAX example</h1>
<button onclick="callAjax()" >Ajax</button>
<div id="d" name="d"></div>
</body>
</html>
// This is my javascript file named jscript.js
function callAjax(){
alert("ajax method called");
if (window.active)
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function(){
if(xhr.readyState==4 && xhr.status==200){
document.getElementById("d").innerHTML=xhr.responseText;
}
};
xhr.open('GET','ajax.php',true);
xhr.send();
}
// This is my server side PHP code named ajax.php
<?php
echo "Welcome to AJAX world";
?>