0

I am using a script i wrote to get search results displayed underneath in the page, now this works okay i guess but when i type in a long sentance all the request get send to the server and ofcourse the response comes way later and gets kind of stacked up resulting in a fast changing div that i wanted to use to show results in, this is really ugly and annoying and i can't really find any examples on the internet about this.

Here is my AJAX script that triggers the ajax call.

$(".harmster_form_replace_onchange input[type=text]").live("keyup paste", function(e){

    if($(this).val().length >=2 || e.keyCode==8)
    {
        var form = $(this).closest('form');
        var target = $(form).attr("target");
        loader_img(target);
        var url = $(form).attr('action');
        $($(form).attr("target")).hide();
            $($(form).attr("target")).fadeIn('fast', function(){
            $.post(url, $(form).serialize(), function(data){
                $(target).html(data);
            });
        });
    }
    return false;
});
Jacta
  • 507
  • 6
  • 17
Hawiak
  • 553
  • 1
  • 9
  • 32

1 Answers1

0

What I've done in the past is create a short delay before hitting the server. Here's some examples of doing it using jQuery:

How to delay the .keyup() handler until the user stops typing?

Community
  • 1
  • 1
Joe McBride
  • 3,789
  • 2
  • 34
  • 38