I\'m trying to call my remote url with added attributes to the url.
For now I have this working:
$(\'#league\').typeahead({
remote: \'/typeah
Hieu Nguyen solution will not work for %QUERY wildcards. According to Bloodhound.js documentation,
replace – .... If set, no wildcard substitution will be performed on url.
Bloodhound docs on github
So %QUERY will be passed as string without being replaced by text entered from user.
So you should put typeahead value into your url :
$('#league').typeahead({
remote: {
url: '/typeahead/get_league?query=%QUERY',
replace: function () {
var q = '/typeahead/get_league?query=' + $('#league').val();
if ($('#sport').val()) {
q += "&sport=" + encodeURIComponent($('#sport').val());
}
return base_url + q;
}
},
limit: 10
});