我想在我的血腥请求中添加一个自定义标题,这是我的代码,但它不起作用.
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' } });
任何的想法?
为typeahead.js v0.11.0添加自定义标头的方法是:
var bloodhound = new Bloodhound({ datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.value); },remote: { url: 'https://server/api/v1/clients?auth_token=3000193534a97fc4a252ddfc966e3ef178c071e4079d35ce4b',settings) { settings.url = settings.url + '&q=' + query settings.headers = { "Authorization": "Basic " + btoa("username:password") }; return settings; } },limit: 5 });