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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:39:45+00:00 2026-05-30T04:39:45+00:00

Context I use jQuery UI autocomplete with a remote datasource. The source send data

  • 0

Context

  • I use jQuery UI autocomplete with a remote datasource.
  • The source send data in this format: [{'label':'Bob', 'id':'03362548'}, {...}].
  • I display a loader gif when the search begin.
  • Data filtering is done serverside.
  • I want to hide the loader gif if no results (the server send []).

Question

How to detect if the search has no results for hiding the loader gif?

Code

jquery:

$('#redir-output').autocomplete({
    source: 'php/ajax/autocomplete.php',
    search: function(event, ui) {
        $('#redir-loader').show();
    },
    open: function(event, ui) {
        $('#redir-loader').hide();
    },
    select: function(event, ui) {
        $(this).attr('name', ui.item.id);
    }
});
  • 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-30T04:39:46+00:00Added an answer on May 30, 2026 at 4:39 am

    By default, when the plugin displays the results, it checks if there’s data to show. In the case there isn’t, it closes the menu.

    _response: function(content) {
        if (!this.options.disabled && content && content.length) {
            ...
        } else {
            // it closes the menu when content.length == 0 (no data)
            this.close();
        }​
    

    Closing the menu raises the “close” event, so I though you could use it. However, the close event is only triggered when the menu is visible:

    close: function(event) {
        clearTimeout(this.closing);
        // as the menu might not be visible at that moment, this is reliable
        if (this.menu.element.is(":visible")) {
            ...
            this._trigger("close", event);
        }
    }​
    

    I think you will have to use the source as a callback and implement yourself the ajax request. Using the “complete” callback, you can hide the loading icon, which in any case should be hidden when the request is over, data returned or not:

    $('#redir-output').autocomplete({
        source: function(request, response) {
    
            $.ajax({
                url: 'php/ajax/autocomplete.php',
                data: request,
                dataType: "json",
                success: function(data, status) {
                    response(data);
                },
                error: function() {
                    response([]);
                },
                complete: function() {
                    $('#redir-loader').hide();
                }
            });
    
        },
    
        ,
        search: function(event, ui) {
            $('#redir-loader').show();
        },
        open: function(event, ui) {
            $('#redir-loader').hide();
        },
        select: function(event, ui) {
            $(this).attr('name', ui.item.id);
        }
    });?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
Is there a way to use data from the current context to filter nodes
I wrote code that fails to use the JQuery autocomplete to fire a result
I am making use of jQuery's .autocomplete plugin, and I would appreciate some assistance
I'm trying to use the new autocomplete function in jQuery UI, but I'm having
I am trying to use the autocomplete script on http://www.devbridge.com/projects/autocomplete/jquery/ . Now, the downloaded
I am trying to use jquery DataTables plugin to display details from my db
Im trying to use this jQuery script and this is confusing me: function CallService()
I am trying to use the jquery autocomplete plugin but am having trouble getting
jQuery Autocomplete works by putting a select box on the page and doing this:

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.