Jquery autocomplete loops HTTP requests
I have a problem with the JQuery autocomplete plugin.
It's hard for me to 开发者_开发技巧explain but whenever I try to press a key it keeps looping with requests to the server.
See:
http://members.lycos.nl/saccon/loop.jpgIt should only request once! Can anyone help me please?
You have created a loop by wrapping the $(document).ready
call in another function AutoCompleteStations
the code should appear as below.
Also you don't need to call a function from the input directly, so you can remove the onkeyup event from the input tag.
$(document).ready(function() {
$("#stations").autocomplete('http://' + server + '/Ajax/ajaxstations', {
minChars: 2, lineSeparator: '\n', cellSeparator: '|', extraParams: {
'countryId': function() {
return $("#countries option:selected").val();
}
},
formatItem: function(row) {
return row['value'];
}
});
});
精彩评论