Solution:
The problem is that in my php code, I have a debug message: print $_GET[‘term’];
It also return the result to client.
I am implementing search with autocomplete feature, but hitting some issues when connecting to php, here is my code
html:
<input type="text" id="leaderboard_search" />
search.js:
jQuery(function($) {
$( "#leaderboard_search" ).autocomplete({
minLength: 1,
width: 240,
source: 'search.php'
});
});
search.php:
<?php
$values = array('abc','def');
echo json_encode($values);
?>
When I type something. It just doesn’t show anything. I have debugged into php code, search.php get called with no problem. So I suspect the problem is on jquery side.
I am using jqueryui 1.8
Update: to simplify the problem, I changed to embedded js, but still doesn’t work:
html code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script>
$(function() {
$( "#leaderboard_search" ).autocomplete({
minLength: 2,
width: 240,
source: 'search.php'
});
});
</script>
<html>
<fieldset class="searchinput"><input type="text" id="leaderboard_search" /></fieldset>
</html>
according to the jquery documentation here http://jqueryui.com/demos/autocomplete/
it states that the result either can be a name value pair or just an array or strings.. so instead u shud echo smthing like this.