ajax_example1.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function showdetail(id)
{
//var xmlhttp;
//if(window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
/*else if(window.ActiveXObject)
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");*/
xmlhttp.open("GET","data_fetch.php?id="+id,true);
xmlhttp.send(null);
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
{
//if(xmlhttp.status==200)
{
//if(xmlhttp.responseText!='')
{
//document.getElementById('emp_nm').innerHTML=xmlhttp.responseText;
xmldoc=xmlhttp.responseXML;
document.getElementById("emp_nm").innerHTML=xmldoc.getElementsByTagName("emp_nm")[0].firstChild.data;
document.getElementById("dpt_nm").innerHTML=xmldoc.getElementsByTagName("dpt_nm")[0].firstChild.data;
document.getElementById("wrkphour").innerHTML=xmldoc.getElementsByTagName("wrkphour")[0].firstChild.data;
document.getElementById("sal").innerHTML=xmldoc.getElementsByTagName("sal")[0].firstChild.data;
document.getElementById("ph_no").innerHTML=xmldoc.getElementsByTagName("ph_no")[0].firstChild.data;
}
}
}
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<select name="select_name" size="1" id="select_name" onChange="showdetail(this.value);">
<?php
$conn=mysql_connect('localhost','root','') or die("Couldn't connect to server.");
mysql_select_db('developer',$conn) or die("Couldn't connect to database");
$sql="select emp_id from emp_detail";
$res=mysql_query($sql) or die("Couldn't execute query.");
while($arr=mysql_fetch_array($res))
{
echo "<option value=$arr[0]>$arr[0]</option>";
}
mysql_close($conn);
?>
</select>
</form>
<div id='emp_nm'></div>
<div id='dpt_nm'></div>
<div id='wrkphour'></div>
<div id='sal'></div>
<div id='ph_no'></div>
</body>
</html>
and other file i.e data_fetch.php as
<?php
$id=$_GET;
$conn=mysql_connect('localhost','root','') or die("Couldn't connect to database.");
mysql_select_db('developer',$conn) or die("Couldn't select database.");
$sql="select * from emp_detail where emp_id='$id'";
$res=mysql_query($sql) or die("Couldn't execute query");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<emp>";
while($arr=mysql_fetch_array($res))
{
//echo "<empid>".$arr[0]."</empid>";
echo "<emp_nm>".$arr[1]."</emp_nm>";
echo "<dpt_nm>".$arr[2]."</dpt_nm>";
echo "<wrkphour>".$arr[3]."</wrkphour>";
echo "<sal>".$arr[4]."</sal>";
echo "<ph_no>".$arr[5]."</ph_no>";
/*echo $arr[1];
echo $arr[2];
echo $arr[3];
echo $arr[4];
echo $arr[5];*/
}
echo "</employee>";
mysql_close($conn);
?>
But i dont get any output and get error as
xmldoc has no properties
document.getElementById("emp_nm").innerHTML=xmldoc.getElementsByTagName("em...
please send me error...