I'm currently doing a live search form based on Jquery/ajax/php, but it dosent seems to work. Can you guys se a problem in my code? :)
function getStates(value) {
$.post("search.php",{ partialState: value }, function(data) {
$("#results").html(data);
});
}
<input type="text" onkeyup="getStates(this.value)" />
<div id="results"></div>
Search.php:
$partialStates = $_POST['partialState'];
$states = mysql_query("SELECT institution_name FROM sb_institutions WHERE institution_name LIKE '%$partialStates%'");
while($stateArray = mysql_fetch_array($states)) {
echo "<div>" . $state['institution_name'] . "</div>";
}
Thanks! :)
Your Code looks ok.
The best way to troubleshoot ajax is to use Firefox with Firebug extension.
That way you can see :
if the function is being fired
if the $_POST values are good : url + parameters
what the server sends as a response
if you have errors in your js
All this will be in the console tab of firebug. after installing firebug right click on the page and choose debug with firebug.