I am using Bootstrap tagsinput and typeahead, which works perfectly when I use it this way:
$(document).ready(function() {
$('.tagsinput-typeahead').tagsinput({
typeahead: {
source: $.getJSON('/ajax/tags.php'),
afterSelect: function() {
this.$element[0].value = '';
}
}
});
});
But I want to use it with ajax, but it only shows me the first letter.
$(document).ready(function() {
jQuery('.tagsinput-typeahead').tagsinput({
typeahead : {
source: function (query, process) {
return jQuery.get('/ajax/tags.php?query=' + query, function(data){
// return process(data);
});
}
}
});
});
Even when I return process(data); it won't work.
In addition when I click on one suggestion the letter will appear in the inputfield as well.
My tags.php looks like this:
$json = [];
$json[] = "test";
$json[] = 'Washington';
$json[] = 'London';
$json[] = 'Germany';
$json[] = 'Denmark';
echo json_encode($json);
Any ideas?
