Typeahead/Bloodhound-对远程使用Jquery Ajax只会导致一个服务器端请求
我需要在Bloodhound的remote属性中使用jQueryAjax设置,因为我有一个只接受POST请求的服务器端页面。每件事都有效,但只有一次。对typeahead输入框中文本的任何后续更改都会调用filter函数,但不会触发新的服务器端请求以获取新数据。它只是过滤它在第一个请求中获得的数据。我需要它提出一个新的要求,因为用户删除文本和其他类型的东西 我刚开始打字,我花了太多的时间试图弄明白这一点。这是我的密码Typeahead/Bloodhound-对远程使用Jquery Ajax只会导致一个服务器端请求,typeahead,bloodhound,Typeahead,Bloodhound,我需要在Bloodhound的remote属性中使用jQueryAjax设置,因为我有一个只接受POST请求的服务器端页面。每件事都有效,但只有一次。对typeahead输入框中文本的任何后续更改都会调用filter函数,但不会触发新的服务器端请求以获取新数据。它只是过滤它在第一个请求中获得的数据。我需要它提出一个新的要求,因为用户删除文本和其他类型的东西 我刚开始打字,我花了太多的时间试图弄明白这一点。这是我的密码 var users = new Bloodhound({ da
var users = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'fake.jsp',
filter: function (users) {
return $.map(users, function (user) {
return {
value: user.USER_ID,
name: user.DISPLAYNAME
};
});
},
ajax: {
type: 'POST',
data: {
param: function(){
return $('#userid').val();
}
},
context: this
}
}
});
users.initialize(true);
$('#userid').typeahead({
minLength: 3,
highlight: true
}, {
name: 'userslist',
displayKey: 'name',
source: users.ttAdapter()
});
我有相同的解决方案,发现jQuery的
缓存:false无论出于何种原因,代码>选项在这种情况下不起作用。以下是我找到的解决方案:
remote: {
url: ...
replace: function(url, query) {
return url + "#" + query; // used to prevent the data from being cached. New requests aren't made without this (cache: false setting in ajax settings doesn't work)
}
}
试试这个:
remote: {
url: 'fake.jsp/?' + Math.random(),
.
.
.
这并不是真正的解决方案,但至少每次刷新页面时都会从服务器获取结果。我解决了这个问题。需要使用猎犬的clearRemoteCache方法。具体在哪里使用clearRemoteCache()?