I'd like to ask how I could add extra params for the AJAX call made by remote
option. I have following simple form to search for qualification (it's in Coffeescript):
$('#search_qualification').typeahead
name: 'qualification'
limit: 50
remote:
url: "/search/qualification?term=%QUERY"
I'd like to send another param with the AJAX call, that is state
, normally with jQuery AJAX call, I'd do this:
$.ajax
url: "/search/qualification"
dataType: "json"
data:
term: request.term
state: $("#state").val()
I am totally clueless in adapting this for typeahead.js, can someone please help me out here? Many thanks
Use the replace
option:
$('#search_qualification').typeahead({
name: 'qualification'
limit: 50
remote: {
url: '/search/qualification?term=%QUERY&state=%STATE'
replace: function(url, query) {
var state = encodeURIComponent($('#state').val());
return url.replace('%QUERY', query).replace('%STATE', state);
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With