I am trying to learn Ajax/JavaScript and I can not seem to get my search to work. It is meant to return partial names but returns nothing at all
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js></script>
<script type="text/javascript">
function getName(value) {
$.post("searchbar.php", {partialName:value},function(data))
$("#results").html(data);
}
</script>
</head>
<body>
<input type="text" onkeyup="getName(this.value)"/>
<br>
<div id="results"></div>
</body>
</html>
php file:
<?php
include "header.php";
$partialName = $_POST['partialName'];
$name = mysql_query("SELECT username FROM grpgusers WHERE username LIKE '%$partialName%'");
while($names = mysql_fetch_array($name)){
echo "<div>".$names['username']."</div>";
}
?>
could some one please help me out on where I am going wrong?
you are missing braces, change to:
function getName(value) {
$.post("searchbar.php", {partialName:value},function(data) {
$("#results").html(data);
});
}
Plus, missing a quote in
jquery.min.js ></script>
^ right there
change that to jquery.min.js"></script>
Missing closing double quote in <script>
tag and closing brace for $.post()
function :
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function getName(value) {
$.post("searchbar.php", {partialName: value}, function (data) {
$("#results").html(data);
});
}
</script>
</head>
<body>
<input type="text" onkeyup="getName(this.value)"/>
<br>
<div id="results"></div>
</body>
</html>
Turns out I did not double quote the link to the js libary thanks