Hi. I am trying a simple example to pull some text from a database via AJAX. I am following this example [url]http://www.w3schools.com/PHP/php_ajax_database.asp
The javascript and form are here:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “
<html xmlns=”
<head>
<script type=”text/javascript”>
var xmlHttpfunction showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert (“Browser does not support HTTP Request”)
return
}
var url=”getuser.php”
url=url+”?q=”+str
url=url+”&sid=”+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open(“GET”,url,true)
xmlHttp.send(null)
}function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState==”complete”)
{
document.getElementById(“txtHint”).innerHTML=xmlHttp.responseText
}
}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>
<form>
Select a User:
<select name=”users” onchange=”showUser(this.value)”>
<option value=”1″>1</option>
<option value=”2″>2</option>
<option value=”3″>Glenn Quagmire</option>
<option value=”4″>Joseph Swanson</option>
</select>
</form><p>
<div id=”txtHint”><b>User info will be listed here.</b></div>
</p></body>
</html>
</body>
</html>
and the php code is here getuser.php
<?php
define(‘MY_CODE’,TRUE);
require(‘globals/functions.gbl.php’);
require(‘classes/templates/templates.class.php’);
require(‘config/config.cfg.php’);
require(‘globals/db.gbl.php’);
require(‘globals/common.gbl.php’);
require(‘globals/logindata.gbl.php’);
require(‘globals/stats.gbl.php’);
$q=$_GET[“q”];
$sql=”SELECT * FROM mi_users WHERE user_id = ‘”.$q.”‘”;
$result = mysql_query($sql);
echo “<table border=’1′>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>”;
while($row = mysql_fetch_array($result))
{
echo “<tr>”;
echo “<td>” . $row[‘user_name’] . “</td>”;
echo “<td>” . $row[‘user_email’] . “</td>”;
echo “</tr>”;
}
echo “</table>”;
?>
The php code is fine as i ahve checked it. For some reason when i change the drop down menu, no results are displayed.