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.

Recommended Answers

All 2 Replies

Hi,

Your code looks alright and should work. I think the problem lies in how you approach the page. When you look at your address bar when you are at request.html, is there a file path (e.g. C:\some\folder\request.html)? If so, you need to go to the file via the localhost: type in the address bar http://localhost/some/folder/request.html and try it again.

If the above is not working, just open demo_get.php in your browser using the localhost and tell me what is echoed in the source code (you know, right click -> source code)

~G

Graphix: Hi,

Your code looks alright and should work. I think the problem lies in how you approach the page. When you look at your address bar when you are at request.html, is there a file path (e.g. C:\some\folder\request.html)? If so, you need to go to the file via the localhost: type in the address bar [url]http://localhost/some/folder/request.html[/url] and try it again.

If the above is not working, just open demo_get.php in your browser using the localhost and tell me what is echoed in the source code (you know, right click -> source code)

~G

Hi,

I realized the problem was here:

function loadXMLDoc()
{var xmlhttp;
if (window.XMLHttpRequest)   //checks if browser supports XMLHttpRequest object {//code for [COLOR="Red"]IE9,IE8[/COLOR],IE7, Firefox, Chrome, Opera, Safari        
          xmlhttp=new XMLHttpRequest(); 
          }
else    {//code for IE6, IE5        
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");   
          }

since i'm using IE9, i had to add IE9 to the above comment.

thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.