Hi,
I'm new to AJAX and i'm trying to make my first AJAX request response program work. My code works fine in Mozilla Firefox. However, it is not working in IE9.
The following is the result i'm getting in IE9:
today is July 11, 2011, 10:55 am
Notice: Use of undefined constant fname - assumed 'fname' in C:\wamp\www\Ajax\demo_get.php on line 4
Notice: Use of undefined constant lname - assumed 'lname' in C:\wamp\www\Ajax\demo_get.php on line 4
hello fnameand lname!
does anyone know on what i'm doing wrong?
the following is my code:
request.html
<script type="text/javascript">
function loadXMLDoc()
{var xmlhttp;
if (window.XMLHttpRequest) //checks if browser supports XMLHttpRequest object
{//code for IE7, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{//code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
//when async=true, the function in onreadystatechange event executes when the response is ready
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "demo_get.php?fname=Henry&lname=Ford",true);
xmlhttp.send();
}
</script>
</head>
<body>
<button type="button" onclick="loadXMLDoc()">REquest Data</button>
<div id="myDiv">
</div>
</body>
</html>
demo_get.php
<?php
$today = date("F j, Y, g:i a");
echo "today is ".$today;
$fname=$_GET['fname'];
$lname=$_GET['lname'];
echo "<br>hello ".$fname. " and ".$lname."!";
?>
thank you.