I'm trying to branch out into Ajax calls for some of my MySQL queries on a Wordpress site I run. To do this I've been following the example here.
I haven't modified the javascript component, only the form
and then I'm using a very simple snippet of php to see if $q is getting fed to php or not.
On page startup I'm getting the correct echo ALL
however on selecting anything in the dropdown menu I'm finding that there is no change in the echo of $q.
What am I missing here? I'm using Google Chrome as my browser if that is an issue.
<html>
<head>
<script type="text/javascript">
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
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 (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a team:</option>
<option value="HAW">Hawks</option>
<option value="GEE">Cats</option>
<option value="ADE">Crows</option>
<option value="WCE">Eagles</option>
</select>
</form>
<br>
<div id="txtHint"><b>Team info will be listed here...</b></div>
</body>
</html>
My simple php code is:
$q = $_GET['q'] ?: 'ALL';
echo $q;