Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7016727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:49:22+00:00 2026-05-27T22:49:22+00:00

I’m having trouble understanding how JQueryUI’s autocomplete function deals with repeated keypresses resulting in

  • 0

I’m having trouble understanding how JQueryUI’s autocomplete function deals with repeated keypresses resulting in asynchronous results. I needed something with similar functionality to it, but I can’t get the autocompleted results to come in properly. An Example:

$(document).ready(function() {
    $('#textinput').live('keyup', function() {
        $.get('bacon.php', function(data) {
             $('#holder').html(data);
        });
    });
});

The problem is that if type quickly, the results often do not come back in the right order. If I type the word ‘KEY’, I may get back results for ‘K’, then ‘KEY’, and then ‘KE’, messing up the content of #holder. I notice that the JQueryUI autocomplete does not have this issue, but I can’t understand how it handles it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:49:23+00:00Added an answer on May 27, 2026 at 10:49 pm

    I haven’t looked at jQuery’s Autocomplete functionality with respect to this particular issue, but what I do with my custom autocompletion scripts is I abort the XHR request if another keypress has been hit within a certain time frame. Something like this:

     var xhr, throttle;
    
     $('.autocomplete').keyup(function() {
          var $this = $(this);
          if (throttle)
             clearTimeout(throttle); // Clear the previous request
          xhr.abort(); // Abort the last XHR request
          throttle = setTimeout( function() {
              xhr = $.getJSON('autocomplete.php', { data: $this.val() }, function(data) {
                  // do something with response
              });
          }, 250); // wait 250 milliseconds before running this
     });
    

    Basically, the throttle makes sure we wait 250 milliseconds before sending the request, in case the user is still typing (you can set this to whatever). The “xhr” variable keeps the XMLHttpRequest in a variable, and if we get another keypress and the response hasn’t come back yet, then we abort the previous one, making sure that only the latest one actually comes back with a response.

    Hope that helps.

    Good luck 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.