I am trying to perform a simple AJAX request from a table but when I var dump the result comes back as undefined?
Here is the JS:
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
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","actions/teamData.php?q="+str,true);
xmlhttp.send();
}
I have created a form that select strictly against ID 1 because when trying to do this dynamically with Php it was doing the same so I have set it to 1 to be sure for now:
<option value="1">' . $row['name'] . '</option>
this is the php doing the request:
$q = intval($_GET['q']);
var_dump($_GET);
$sql = "SELECT * FROM team WHERE id = ' " . $q . " ' ";
$result = mysqli_query($conn,$sql);
echo "<table>
<tr>
<th>Team name</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
I have a valid connection which has been tested. But the result comes back as:
array(1) { ["q"]=> string(9) "undefined" }