Hi,
I am trying to use AJAX to do a simple thing of displaying the results in the same page. Clicking on the <a href tag should display the results in the same page. This is working correctly in IE but the onclick() function is not working in firefox and safari. Below is the code, any help appreciated.
index.php
<?php
include "dbconnect.php";
?>
<html>
<head>
<script language="JavaScript" type="text/javascript">
function display_data(id) {
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null) {
alert ("Your browser does not support AJAX!");
return;
}
var url="ajax2.php";
url=url+"?employ_id="+id;
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") {
document.getElementById('employ_data').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function GetXmlHttpObject() {
var xmlhttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlhttp=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlhttp;
}
</script>
</head>
<body>
<?php
$query="SELECT AGE, experiment_name XENOID FROM Donor_Experiment limit 10";
$result=mysql_query($query);
while(list($AGE, $XENOID)=mysql_fetch_row($result)) {
echo '<a href="#" value="'.$XENOID.'" onclick="display_data(this.value)">'.$XENOID.'</a>';
}
?>
<div id="employ_data"><div>
</body>
</html>
ajax2.php
<?php
include "dbconnect.php";
$query="select DONOR, SEX, DIAG, SITE from Experiment where experiment_name = '$_GET[employ_id]'";
$result=mysql_query($query);
$employ=mysql_fetch_array($result);
echo "<table border=\"1\">
<tr>
<td>Name:</td>
<td>".$employ[DONOR]."</td>
</tr>
<tr>
<td>Appoint Date:</td>
<td>".$employ[SEX]."</td>
</tr>
<tr>
<td>Country:</td>
<td>".$employ[DIAG]."</td>
</tr>
<tr>
<td>City:</td>
<td>".$employ[SITE]."</td>
</tr>
</table>";
?>