I've seen people configure the AJAX request Bloodhound
is performing in typeahead.js
by including an ajax
object like this on their constructor:
var locsData = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace("name"),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "/locations/search.json?q=%QUERY",
ajax: {
beforeSend: function(xhr, settings) {
// maybe the 'if' is not necessary, but just to be sure...
if ($(document.activeElement).typeahead != null) {
$(document.activeElement).addClass('loading-text');
}
},
complete: function(xhr, status) {
if ($(document.activeElement).typeahead != null) {
$(document.activeElement).removeClass('loading-text');
}
}
}
},
limit: 100
});
However, I've been taking a look at the sources and found no way to configure ajax that way on latest version (v.0.11.1 at this time). I need to turn off ajax
flag global
so it doesn't trigger my loading gifs when sending ajax requests to the server but I can't find out how to do it.
Tried this both ways. You'll notice that I'm using struts2
by the way I specified the URLs:
var engine = new Bloodhound({
remote: {
url: '<s:url value="%{#typeaheadHwsnUrl}"/>'+'%QUERY%',
wildcard: '%QUERY%',
ajax: {
global: false,
}
},
datumTokenizer: Bloodhound.tokenizers.whitespace('q'),
queryTokenizer: Bloodhound.tokenizers.whitespace
});
and also, with no luck tried outside of the remote
object:
var engine = new Bloodhound({
remote: {
url: '<s:url value="%{#typeaheadHwsnUrl}"/>'+'%QUERY%',
wildcard: '%QUERY%',
},
datumTokenizer: Bloodhound.tokenizers.whitespace('q'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
ajax: {
global: false,
}
How can I turn off this global
flag for ajax
calls made by Bloodhound
?