本文介绍了预先输入猎犬的自定义标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的猎犬请求中添加一个自定义标头,这是我的代码,但是它不起作用.

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'
    }
});

有什么主意吗?

推荐答案

为typeahead.js v0.11.0添加自定义标头的方法是:

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 });

这篇关于预先输入猎犬的自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 02:35