javascript - Trouble with ajax delay in search form -
i trying set timeout ajaxget function shown here.
without code have found have:
$('#search').on('keyup', function() { var query; query = $(this).val(); ajaxget('{% url "distributors:search_dist" %}', { 'query': query }, function(content) { $('#distributors').html(content); // alert(content); set_favorite(); }) });
and works nice.
after implemented solution delay have:
var delay = (function() { var timer = 0; return function(callback, ms) { cleartimeout(timer); timer = settimeout(callback, ms); }; })(); $('#search').keyup(function() { delay(function() { var query; query = $(this).val(); ajaxget('{% url "distributors:search_dist" %}', { 'query': query }, function(content) { // $('#distributors').html(content); alert(content); set_favorite(); }) }, 1000); });
but doesn't work. believe problem is js because doesn't run ajaxget()...
any ideas doing wrong?
you create settimeout within event :
$('#search').keyup(function() { window.settimeout(function(){ var query; query = $(this).val(); ajaxget('{% url "distributors:search_dist" %}', { 'query': query }, function(content) { // $('#distributors').html(content); alert(content); set_favorite(); }) },1000); });
Comments
Post a Comment