javascript - jquery Autocomplete is not loading the results correctly and menu doesn't show unless I press down key -
this have:
searchtimeoutid; initquicksearch = function() { $( 'input#quick-search' ).autocomplete({ source: [] }); $('input#quick-search', document).on('keyup', function(e) { switch(e.which) { default: // live search window.cleartimeout(searchtimeoutid); // remove timer var str = $(this).val(); // search string if (str !== '') { // search searchtimeoutid = window.settimeout(livesearch, 100); } break; } }); }; livesearch = function() { var str = $('input#quick-search').val(); if(str !== '') { $.ajax({ type: 'post', url: '/livesearch', data: { query: str }, cache: false, success: function(data){ var results = data.split(','); alert(results); // displays correct results here $( 'input#quick-search' ).autocomplete( 'option', { source: results }); }, error: function(response) { printerror(response); } }); } return false; }; when output results variable using alert(results), values correct.
however, when try , update values in autocomplete not display correct values. also, have press down key menu appear.
$( 'input#quick-search' ).autocomplete( 'option', { source: results });
what doing wrong?
i had change:
searchtimeoutid = window.settimeout(livesearch, 100); to:
livesearch();
Comments
Post a Comment