I already posted this on typeahead github, but I thought that maybe I could ask here and find the answer.
I am trying to use a remote query as our data source for typeahead. To do this, I would like to create a POST and put my request parameters in a payload. When I set the settings.type parameter to POST in the beforeSend function, it works, but when I set the settings.data parameters, I don’t see the data set in my debuggers, and then in my example I use a simple http service that returns your useful load, and it also checks that no data is being sent. Under typeahead.js, jQuery 1.9.1 is used and, in particular, using ajax beforeSend call. As far as I can tell about jQuery ajax api, I set the appropriate values in the typeahead beforeSend function.
Here is my code and it works in jsfiddle http://jsfiddle.net/75mCa/2/
$('.autocomplete-es .typeahead').typeahead({
name: 'es-tags',
remote: {
url: 'http://httpbin.org/post',
beforeSend: function (jqXhr, settings) {
console.log('type is initially : ' + settings.type);
console.log('data is initially : ' + settings.data);
settings.type = 'POST';
settings.data = { fields: ['tags.tag'], query: { prefix: { tag: 'emp' } } }
console.log('type is now : ' + settings.type);
console.log('data is now : ' + settings.data);
return true;
},
filter: function (data) {
console.log(data.data);
console.log(data.data.fields[0]);
}
}
});
Thanks for any help, G