开发者

Jquery autocomplete loops HTTP requests

开发者 https://www.devze.com 2022-12-21 03:52 出处:网络
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.

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:

Jquery autocomplete loops HTTP requests

http://members.lycos.nl/saccon/loop.jpg

It 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']; 
        }
     });
}); 
0

精彩评论

暂无评论...
验证码 换一张
取 消