I created a simple jQuery post that returns data every time an user types in a character in an input field. The problem is that it is not working. Firebug returns no errors. When I type in a keyword FireBug Net shows no requests made. My code is almost a cut and paste from another piece of code that does work. I have no idea what to do and this is not the first time something like this has happened.
Here is the original file.
<input type="text" id="search_tags" />
<div id="tag_results"></div>
<script type="text/javascript" >
$(document).ready(function() {
$('#search_tags').keyup(function() {
var search_term = $(this).val();
$.post('ajax_file.php', {search_term: search_term}, function (data) {
$('#tag_results').html(data);
});
});
$('#search_tags').bind('keydown', function(e) {
if(e.keyCode==13){
e.preventDefault();
};});
});
</script>
Here is the ajax file.
$search_term = sanitize($_POST['search_term']);
if (!empty($search_term)) {
$search = mysql_query("SELECT DISTINCT `tag_name` FROM `tags` WHERE `tag_name` LIKE
'%$search_term%' LIMIT 0, 15");
$y = 1;
while ($results_row = mysql_fetch_assoc($search))
{
echo '<br><br>' . $results_row['tag_name'] . '<br><br><hr>';
$y++;
}}
Well:
$('#search_tags_').keyup(...
should be:
$('#search_tags').keyup(...
because I can't see an element with id="search_tags_"
in your example which has:
<input type="text" id="search_tags" />