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

  • Home
  • SEARCH
  • 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 7048993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:57:32+00:00 2026-05-28T02:57:32+00:00

The Source callback of the autocomplete function takes an request and a response object

  • 0

The Source callback of the autocomplete function takes an request and a response object as parameters. I couldn’t find any useful information for what these object excatly are and what properties and methods they define.

  • 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-28T02:57:32+00:00Added an answer on May 28, 2026 at 2:57 am

    I think the best way to understand what is function(request, response) {...} is to go through the source code of the plugin itself.

    I’ll try to be as clear as possible, tell me if you need more details or explanations.

    1. What is “source”

    When you enter some value in the input, the plugin executes a “search” through the private method “_search”

    _search: function(value) {
        this.pending++;
        this.element.addClass("ui-autocomplete-loading");
    
        this.source({ term: value }, this.response);
    }
    

    Reading the last line, you can see the plugin expects the “source” property to be a function that it executes passing as

    • request: an object-literal with one property term which will contain what was entered in the input

    • response: the plugin property response. This property is a function that by default calls the private method “_response” which is responsible for showing the menu, filtering the list, closing the menu etc.


    2. Using the “source” option

    But reading the documentation, the source option accepts an array or an url for remotely getting the values… so how does this work ?

    The plugin initialize this.source through the private method _initSource:

    _initSource: function() {
        var self = this,
            array, url;
        if ($.isArray(this.options.source)) {
            array = this.options.source;
            this.source = function(request, response) {
                response($.ui.autocomplete.filter(array, request.term));
            };
        } else if (typeof this.options.source === "string") {
            url = this.options.source;
            this.source = function(request, response) {
                if (self.xhr) {
                    self.xhr.abort();
                }
                self.xhr = $.ajax({
                    url: url,
                    data: request,
                    dataType: "json",
                    autocompleteRequest: ++requestIndex,
                    success: function(data, status) {
                        if (this.autocompleteRequest === requestIndex) {
                            response(data);
                        }
                    },
                    error: function() {
                        if (this.autocompleteRequest === requestIndex) {
                            response([]);
                        }
                    }
                });
            };
        } else {
            this.source = this.options.source;
        }
    },
    

    You can see that in both cases the plugin ends up defining this.source as function(request, response) {...}

    • if you provide an array, it executes the response method to display the menu passing a filtered array using request.term:

      this.source = function(request, response) {
          response($.ui.autocomplete.filter(array, request.term));
      }
      
    • if you provide an url, it makes the ajax request and upon success, executes the response method to display the returned data:

      success: function(data, status) {
          if (this.autocompleteRequest === requestIndex) {
              response(data);
          }
      },
      
    • otherwise, it uses the provided option value as it is


    3. When passing a function(request, response) as “source” option value

    So when you call the plugin this way:

    $(...).autocomplete({
        source: function(request, response) { ... }
    });
    

    You’re actually not providing the plugin with any data !

    But you have the opportunity to gather the data the way you want (other that an array or an url), and still have access to the plugin functionnality through the parameters. You have the input content through request.term and you can execute the response callback to display the results.

    Example ? The Autocomplete demo pages…

    If you go to the Autocomplete Multiple values demo page, the jquery ui team uses this functionnality.

    The data is stored in a javascript array var availableTags = [...];

    And they define the source option this way:

    source: function(request, response) {
        // delegate back to autocomplete, but extract the last term
        response($.ui.autocomplete.filter(availableTags, extractLast(request.term)));
    }
    
    1. Filter the availableTags array with a special treatment for handling multiple values in input

    2. call the response function to display the filtered array

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

Sidebar

Related Questions

$(document).ready(function () { $(#example).autocomplete(https://graph.facebook.com/me/friends?access_token= + accessToken + &callback=?, { width: 250, height: 400, max:
Is it possible to determine the source information (file, line number, column number) of
i try using window.attachEvent (or addEventListener) to capture js errors my callback function gets
this thing almost works: function myClass(url) { this.source = url; this.rq = null; this.someOtherProperty
Does anybody know of any examples using AudioQueue that play from an in-memory source?
How does jQuery (JavaScript) and gc work? callBack is a function that runs as
Note that I'm asking about something that will call a callback function more often
I have a jQuery UI Autocomplete control that fires an Ajax request when minLength
I have an autocomplete field using local JSON data. $( #tags ).autocomplete({ source: get_items,
I want to use autocomplete with .live function, but it gives syntax error $(input[name=point]).live(function()

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.