I would like to add a custom header into my bloodhound request, here is my code but it doesn't work.
var datasource = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: url,
prepare: function (query, settings) {
var authHeaders;
settings.type = "POST";
settings.data = param + '=' + query;
settings.headers = {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
};
return settings;
},
wildcard: '%QUERY'
}
});
Any idea?
The way to add custom headers for typeahead.js v0.11.0 is:
var bloodhound = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'https://server/api/v1/clients?auth_token=3000193534a97fc4a252ddfc966e3ef178c071e4079d35ce4b',
prepare: function (query, settings) {
settings.url = settings.url + '&q=' + query
settings.headers = {
"Authorization": "Basic " + btoa("username:password")
};
return settings;
}
},
limit: 5 });
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