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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:04:57+00:00 2026-05-26T06:04:57+00:00

jQuery part: I have a jQuery UI 1.8 Autocomplete form that fetches remote JSON

  • 0

jQuery part:

I have a jQuery UI 1.8 Autocomplete form that fetches remote JSON data from a Rails controller.

$('input#test').autocomplete({
    source: function( request, response ) {
      $.getJSON(
        "<%= find_stuff_url(:format => :json) %>",
        request,
        function(data){
          console.log(data);
          function(data) {
            $.map(data, function(item) {
            return {
              "label" : item.control_point.label,
              "value" : item.control_point.geonames_uri
            }
            });
        });
    },
    minLength: 2,
    select: function( event, ui ) {
        // ...
    }
  });

… what I get returned:

This Rails controller just returns an array of Objects (actually, ActiveRecord instances), serialized into JSON. I would like to use this data to populate the Autocomplete list. Right now, what I receive is an array of serialized ActiveRecord objects – for example one of these objects could be:

Object
  control_point: Object
    geonames_uri: "http://sws.geonames.org/5128581/"
    label: "New York (US)"
    lat: "40.7142691"
    lng: "-74.0059729"
    map_id: 1
    name: "New York City"

What I need:

However, jQuery Autocomplete probably wants a JSON array of objects that carry id and label to populate its list — yet I don’t have these. This is what the documentation says:

A response callback, which expects a single argument to contain the data to suggest to the user. This data […] can be in any of the formats described above for simple local data (String-Array or Object-Array with label/value/both properties).

I don’t quite understand what’s meant by “String-Array or Object-Array with label/value/both” properties.

In this example, my output would be a list of those control_point Objects, shown like:

label: "New York (US)", value: <the geonames_uri>
label: "New York (Somewhere else)", value: <another geonames_uri>
…

I tried to adapt the code from the documentation using $.map, but it doesn’t seem to work (i.e. the autocomplete shows nothing).

How do I pass an arbitrary JSON object to jQuery Autocomplete, so it shows a list of results? More explicitly: What do I have to put in function(data){}?

  • 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-26T06:04:58+00:00Added an answer on May 26, 2026 at 6:04 am

    The documentation (at the same link you posted) explains what is meant by the terms String-Array and Object-Array:

    The local data can be a simple Array of Strings, or it contains
    Objects for each item in the array, with either a label or value
    property or both. The label property is displayed in the suggestion
    menu. The value will be inserted into the input element after the user
    selected something from the menu. If just one property is specified,
    it will be used for both, eg. if you provide only value-properties,
    the value will also be used as the label.

    So at the end of the day, it’s either a String-Array: ["value1", "value2", ...] or an Object-Array:

    [
      { label:"First Value", value:"value1" },
      { label:"Second Value", value:"value2" },
      ...
    ]
    

    You can choose to either make the required server side changes to serialise the data to look appropriate, or map it client side, as in this example. Either way the end result should be one of the above formats.

    So, for example, something like this:

    function(data) {
    response( $.map(data, function(item) {
      return {
      "label" : item.control_point.label,
      "value" : item.control_point.geonames_uri
      }
    }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have a jQuery autocomplete. I have specified some data but when
I am using the jQuery autocomplete plugin and have wired up an input field
I have a form field which uses Jorn Zaefferer's autocomplete jQuery plugin. If i
I have a jquery auto complete script that takes a JSON array and displays
I have a form I'm submitting via ajax with jQuery, it's part of a
We have this anonymous function in our code, which is part of the jQuery's
Can jQuery test an array for the presence of an object (either as part
Following on from my previous two questions: How to make jQuery autocomplete execute a
I have a form that I want to be used to add entries. Once
when i refresh a part of a webpage that has a jquery ui button,

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.