I'm trying to implement a typeahead whose source is an API that expects a GET request with a body of data, not url encoded data. I've tried a few different things in the 'prepare' object, but can't get it to url encode parameters. Is it possible with typeahead, or jquery in general, to have it not do this? I have a feeling jquery maybe just doesn't let you do this, since it would be considered 'bad practice', but changing the API is not really an option!
Here is my code:
$(document).ready(function(){
var people = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'apiUrl',
prepare: function (query, settings) {
settings.type = "GET";
settings.contentType = "application/json";
settings.DataType = "json";
settings.processData = false;
settings.data = JSON.stringify({"search":"people","query":query});
return settings;
}
}
});
$('.typeahead').typeahead(null, {
source: people
});
})
I'm using jquery 1.11.3 & typeahead.js 0.11.1.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…