This is my first question regarding PHP so please bear with me. I’ve been following tutorials from phpacademy.org.
I’m stuck on one tutorial where an intro to AJAX is given. I typed in the exact code as the tutor, still its not working on my end.
I searched alot for it but it didnt help one bit. Could anybody help me out here? Here’s my code:
<html>
<head>
<script type="text/javascript">
function load(){
if(window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementsById('adiv').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open('GET', 'AJAX.inc.php', true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="adiv"></div>
<input type="submit" value="Submit" onclick="load();">
</body>
</html>
And here’s the AJAX.inc.php file:
<?php
echo 'Hello AJAX';
?>
However another example from w3school.com is working.
Possible duplicate:
AJAX not working with XAMPP or is it just impossible
But this question isn’t properly answered (or I dont understand it). Would someone please clarify it?
There is no
document.getElementsByIdmethod.Should be