I create autocomplete with twitter typeahead using an ajax JSON call for my php file to get some data, but it continues to display the following in the dropdown list of results:
undefined
undefined
undefined
but when i do:
alert(data);
I get the necessary data, but somehow the autocomplete list continues to display undefined, read and check several things with some articles here in stackoverflow, but I can not get it to work.
I need to execute the following jquery code:
$('.item-name .typeahead').typeahead(null,{
source: function (query, process) {
$.ajax({
url: 'ajaxItems.php',
type: 'POST',
dataType: 'JSON',
data: 'query=' + query,
success: function(data) {
process(data);
}
});
}
});
And my ajaxItems.php has the following code for testing purpose:
<?PHP
$results = array();
$results[] = 'jeans';
$results[] = 'sweater';
$json = json_encode($results);
print_r($json);
?>
The JSON output is as follows:
["jeans","sweater"]
Hopefully someone can highlight what I'm doing wrong or point me in the right direction. Thanks, advanced!
:
http://twitter.imtqy.com/typeahead.js/releases/latest/typeahead.bundle.js