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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:46:26+00:00 2026-05-24T10:46:26+00:00

I have a search using jquery ui autocomplete which works great. Currently I preload

  • 0

I have a search using jquery ui autocomplete which works great. Currently I preload a json list of cities and countries so that it loads quickly and has no need to poll the server. However now, I’d like to add to my autocomplete search specific names of places ie in my case hotels, restaurants, etc..

My question is should I just ditch the preloaded city and country list and do a plain vanilla ajax database query ?q= as they type, or is it possible and would it be useful to have some sort of hybrid between the two. IE a preloaded list until they reach a certain number of characters or there are fewer than 5 results?

Would it save load time or just be a headache? And if so, how should I go about it?

I originally had it as an ajax query but switched to the preloaded json to speed it up. The complete list of cities and countries is tiny, however the list of places is large. 99.9% of the time people will search for locations and not specific places.

  • 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-24T10:46:27+00:00Added an answer on May 24, 2026 at 10:46 am

    How you would achieve this:

    You could accomplish something like this by passing a function to the source option of autocomplete. Within that function, you would perform some logic to determine if you needed to use an AJAX call or simply filter the data on the client-side:

    $("#tags").autocomplete({
        source: function(request, response) {
            // This is how autocomplete finds matching results by default:
            var results = $.ui.autocomplete.filter(common, request.term);
    
            if (results.length < 5) {
                // Perform an ajax call.
                // In the success method, call response(results)
            } else {
                response(results);
            }
        }
    });
    

    Both of your ideas for a “hybrid” autocomplete using two sources were intriguing. However, while testing out the solution, I encountered a potential usability problem. Normally with this type of control you would expect to get fewer results back as you type.

    For example: lets say your local source array looks like this:

    ['jquery', 'jquery-ui', 'jquery-ajax', 'jquery-plugins']
    

    And you use the strategy of showing more results after, say, 5 characters are typed. After the user types j-q-u-e-r-y, typing the y would trigger an AJAX call, populating the list with more results, which may not be straightforward for the user depending on your use case.

    Example: http://jsfiddle.net/andrewwhitaker/wSBa3/

    I think this gets better when you set some limit on the number of results that can come back from the server. If you sync this value up with the minimum number of results before an AJAX call occurs, the interaction doesn’t seem as funky. In fact, this example makes the concept more plausible to me:

    Example: http://jsfiddle.net/andrewwhitaker/NxELC/


    Is it worth it?

    Would it save load time or just be a headache?

    Maybe both!

    I think this really depends on how resource-intensive the query is, how much data we’re talking about, and also how maintainable a solution like this would be. I can’t really speculate on the first two options, but I would say that you could run into a maintenance problem with maintaining two lists. That problem sort of depends on what server-side technology you’re using. I think if you did it correctly, you wouldn’t have any trouble though.

    Apologies in advance for the lengthy answer, but I hope it helps.

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

Sidebar

Related Questions

I'm using jQuery. I have website feature that does an ajax search and returns
I have an input box for which I am using the Jquery autocomplete function.
Im currently using the JQuery UI extension for its search autocomplete. However, I need
I am using jQuery UI Autocomplete to build a search interface. I have defined
I have a site with a form with autocomplete using jquery. It works fine,
I have a search action that returns a json response object which is basically
I am using jQuery datatables for showing search results. I have some checkboxes which
I'm using jQuery AutoComplete, and I have an auto-complete search box to search for
I have a search box in my application that uses the jQuery UI Autocomplete
(Using MySQL and PHP) I have a search form that will allow my users

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.