0

Here's my code :

options = { 
        source: function(request, response) {
            $.getJSON('@Url.RouteUrl("Search")', { prefixText: request.term, count : 10 }, function (retour) {

                response( retour);


            });
         }

    };
    a = $('#test').autocomplete(options);

If i'm searching for test , when i begin to write the autocomplete does a request for t, te, tes and finally test...

The "test" request finish first so the autocomplete show the good result but 2 sec later ith show the result for "tes"

Is there a way to abort the other request when i'm writing ?

Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
GregM
  • 2,634
  • 3
  • 22
  • 37
  • 1
    You can see this link http://stackoverflow.com/questions/446594/abort-ajax-requests-using-jquery – Calixto Jun 20 '12 at 18:29

1 Answers1

0

Here's the solution (thanks calixto) :

 if(xhr)
            {
                //kill the request
                xhr.abort();
            }

            xhr = $.getJSON('@Url.RouteUrl("Search")', { prefixText: request.term, count : 10 }, function (retour) {

                response( retour);


            });
GregM
  • 2,634
  • 3
  • 22
  • 37