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 7441325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:59:33+00:00 2026-05-29T10:59:33+00:00

I am using jQuery UI autocomplete for a city search on my site. It

  • 0

I am using jQuery UI autocomplete for a city search on my site. It starts to search after the user has entered 3 characters.

I’m wondering how to change this script to abort the last query if the user continues typing.

function enableCitiesAutocomplete() {
    var url = LIST.urls.api_cities_search;

    $('#txt_search_city').autocomplete({
        source: url,
        minLength: 3,
        select: function( event, ui ) {
            $(this).val( ui.item.value );
            $( "#id_city" ).val( ui.item.id );
            $(this).closest('form').submit();
        }
    });
}
  • 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-29T10:59:34+00:00Added an answer on May 29, 2026 at 10:59 am

    I don’t know if you can “abort” a completion that has already begun. But you may be able to get what you want by interrupting the render part of the autocomplete. This might work if the autocomplete consists of a query and a render, and the query involves a network transaction.
    If there’s a query and a render, and the query is just a search through a locally-stored list, then this probably won’t work, because the latency is too low.

    This SO question describes how to monkey-patch the renderMenu and renderItem fns in the jQuery autocomplete package. I’m thinking you can use the same monkey-patch approach.

    You’d need to specify, as the source, a function, not a URL. This SO question describes how. Then, in that function, increment a count variable that says “a search is in process”. Then perform the search by doing an “ajax get”. Also patch the renderMenu to (a) only render if a single search is in process, and (b) decrement the search count.

    It will probably look something like this:

    var queriesInProcess = 0;
    var ac = $('#txt_search_city').autocomplete({ 
        minLength: 3, 
        select : .... ,
        // The source option can be a function that performs the search, 
        // and calls a response function with the matched entries. 
        source: function(req, responseFn) { 
            var url = baseUrl + req.term;
            queriesInProcess++;
            $.ajax({
              url: url,
              //data: data,
              success: function(json,xhr) {
                  queriesInProcess--;
                  var a = ....retrieve from the json .... 
                  responseFn( a ); 
                },
                errpr : function () { queriesInProcess--; },
              dataType: 'json'
            });
        } 
    }); 
    
    ac.data( "autocomplete" )._renderMenu = function( ul, items ) { 
      if (queriesInProcess > 0) return; 
      var self = this; 
      $.each( items, function( index, item ) { 
        self._renderItem( ul, item ); 
      }); 
    }; 
    

    If you want to get more sophisticated, you can also try to abort the pending ajax request.
    This would need to happen in the source function; you’d need to cache/stash the XHR returned from the $.ajax() call, and call abort() when a new one comes through.

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

Sidebar

Related Questions

I'm using Jquery autocomplete. If a user types 2 characters then waits, then types
I'm developing a form, and using jQuery UI Autocomplete. When the user selects an
I am using Jquery autocomplete in my form. After selecting the value from autocomplete,
I've been using the JQuery Autocomplete plugin with JQuery version 1.3.2, and it has
I am using jQuery Autocomplete to search a local database of cities. Here is
I'm using jQuery autocomplete for a search field. When the autocomplete source returns a
I am using jQuery UI Autocomplete with ASP.NET like this : First I am
I am using jQuery auto-complete. I have download this script from http://code.google.com/p/jquery-autocomplete/ . I
I have a site with a form with autocomplete using jquery. It works fine,
I'm using jQuery autocomplete control to perform search on three entities: Owner, Manager and

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.