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

Recommended Answers

All 3 Replies

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.

commented: Reasoning +1

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

[object XMLHttpRequest]

.

Please help me. Thanks in advance.

<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

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.