2

Alright, hoping someone can help. I've got a page used to search for employees. The requirement is that the search pulls back results as you type. Maybe I'm going about this the completely wrong way, but I currently have working code. The problem is that some results are returned out of sequence.

For instance, you may be searching for 'Don', but the results for 'Don' will be returned before you get the results for 'Do', leaving the results for 'Do' on the screen.

Is there any way to clear/cancel any pending results when beginning a new search so that I only get the most current results?

Here is the code:

    $('#searchString').keyup(function () {
        searchPeople($(this).val());
    });

    function searchPeople(searchString) {
        var bu = $('#selectedBU').val();
        $('#people_view').clearQueue().load(
            '@Url.Action("PeopleView", "People")',
            { SearchString:searchString.replace(' ', '*|*'),
              bu:bu });
        $('#searchString').focus();
    }
tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

I would use jquery autocomplete as to not reinvent the wheel :)

If you still want to implement your own autocomplete, you have to stop the previous ajax request(s). You can start here and also have a look at the linked question for even more suggestions.

Community
  • 1
  • 1
Alexandros B
  • 1,881
  • 1
  • 23
  • 36
  • For clarification, this returns a grid of employee photos, and as you type the grid contains less photos. jquery autocomplete doesn't seem to fit exactly. Thanks for the link though! – RazorbackRich Jan 20 '12 at 14:42
  • you can have autocomplete return a list of `img` elements. – Alexandros B Jan 20 '12 at 15:50
  • thanks! The linked post regarding the previous ajax request(s) got me on the right track. I knew there had to be something along those lines! – RazorbackRich Jan 20 '12 at 17:57