0

Hi Friends,

Please check this code where i was did wrong ? thanks in advance.

<button type="button" onclick='showData()'>Edit</button>
<script type="text/javascript">
			function showData()
			{
			if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
				document.getElementById("emp_body").innerHTML=xmlhttp.responseText;
				}
			  }
			xmlhttp.open("GET","../xmlData/sample.php",true);
			xmlhttp.send();
			alert("Its Working");
			}
			</script>

The Alert code at the end of the code is displaying but the xmlhttp.open is not working.. please help

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by rayidi
1

The alert() function does nothing to check whether your xmlhttp is working. Is your xmlhttp variable global? In other words, do you declare it somewhere and is being used somewhere else too? The reason is that I do not see you declare the object inside your function at all. In JavaScript, simply use a variable name in a function results in creating/assuming the variable is global - dangerous.

Let see if you actually get xmlhttp object created by inserting alert(xmlhttp) right before line 12.

Votes + Comments
Reasoning
0

I had used so many xmlHttp finctions. when i was wrote alert(xmlHttp) its printing

[object XMLHttpRequest]

.

Please help me. Thanks in advance.

0
<div class='emp_body' id='fields'>

Got it. I didn't mention the id. i thought the class is the id. now its working fine.

Thanks All

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.