Is there something wrong with this code?
Form input:
<input type="text" id="currentTag" name="currentTag" class="inputbox"/>
jquery:
$("#currentTag").autocomplete({
source:'getautocomplete.php',
minLength:1
});
getautocomplete.php
$term=$_GET["term"];
$query=mysql_query("SELECT * FROM table_name WHERE tag_value LIKE '%".$term."%' ORDER BY tag_value ");
$results=array();
while($row = mysql_fetch_array($query)){
$results[] = array('label' => $row['tag_value']);
}
echo json_encode($results);
getautocomplete.php output when script is called directly:
[{"label":"birdseye"},{"label":"doggy"},{"label":"tomhat"}]
'SOLVED' It's a bit of a hack job, but I ended up setting source as a jquery var instead of url. Then used php include to echo the json into the var. All this in a Joomla site. Some conflict that I don't understand was happening, because the above code worked in a test file outside of Joomla. If anyone knows the conflict I'd curious to learn. Cheers.
$(document).ready(function() {
$( "#currentTag" ).autocomplete({
source: tags
});
});
var tags = <?php include("getautocomplete.php");?>;