If I use
var users_bloodhound = new Bloodhound({
datumTokenizer: function (datum) {
return Bloodhound.tokenizers.whitespace(datum.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {url:'https://cdn.rawgit.com/twitter/typeahead.js/gh-pages/data/countries.json',
filter: function (result) {
return $.map(result, function (username) {
return {
name: username
};
});
}
}
});
with the json formatted as ["Andorra","United Arab Emirates","Afghanistan",...] it works as expected, but I can't manage to receive the data returned by my .php file with
var users_bloodhound = new Bloodhound({
datumTokenizer: function (datum) {
return Bloodhound.tokenizers.whitespace(datum.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {url:'./search.php?query=%QUERY',
wildcard: '%QUERY',
filter: function (result) {
return $.map(result, function (username) {
return {
name: username
};
});
}
}
});
(I only changed the part after remote...) The .php file receives the input and logs for example ["test01","test02"] as answer to the input 't'. The last two lines of my php file are:
error_log(json_encode($results));
return json_encode($results);
So, how do I make my JS function receive the return value of my php file?
instead of returning
json_encode
have you tried echoing
it, and commenting out the error log to see what happens?
//error_log(json_encode($results));
echo json_encode($results);