Twitter Type Aaax results undefined

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) {
            // alert(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

+3
4

source:, remote:. :

$('.item-name .typeahead').typeahead({
    remote: 'ajaxItems.php?query=%QUERY'
  });

, null typeahead(null,{, , , . , $_GET $_POST, , .

+1

. , , /, "", :

[{'value': 'first', 'value': 'second', 'value': 'third'}]

, typeahead , , displayKey, ' .

+3

- ian, ( ). :

[{'value': 'first'}, {'value': 'second'}, {'value': 'third'}]
+3

, typeahead . JSON!

$.makeArray() :

success: function(data){
     process($.makeArray(data));
}

, JSON.parse() ?

, :)

0

All Articles