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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:05:40+00:00 2026-06-17T17:05:40+00:00

I am trying to setup my Jquery UI autocomplete field to have data from

  • 0

I am trying to setup my Jquery UI autocomplete field to have data from an ajax connection. Here is my code so far:

            $("#mainIngredientAutoComplete").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: "../api/IngredientChoices",
                        dataType: "json",
                        success: function (data) {
                            response(function (item) {
                                return {
                                    label: item.MainName,
                                    value: item.MainItemID
                                }
                            });
                        }
                    });
                }
            });

This is my JSON:

[{"SubItemID":1,"MainItemID":1,"SubName":"2%","MainName":"Milk"},{"SubItemID":2,"MainItemID":1,"SubName":"Skim/Fat Free","MainName":"Milk"},{"SubItemID":3,"MainItemID":2,"SubName":"Chedder","MainName":"Cheese"}]

HTML:

<table id="tbl_ingredients" style="padding:0px;">
                <tr id="ingHeader">
                    <td>Ingredient</td>
                    <td>Measurement</td>
                    <td>Amount</td>
                    <td><input id="mainIngredientAutoComplete" /></td>
                    <td></td>
                </tr>
</table>

When I start to type “mil” (for milk) my code gives me this error:

enter image description here

EDIT:

I made your change, which worked for a few attempts but now I am getting a new error –

Unhandled exception at line 55, column 25 in [URL]

0x800a1391 – Microsoft JScript runtime error: ‘data’ is undefined

        $("#mainIngredientAutoComplete").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "../api/IngredientChoices",
                    dataType: "json",
                    response: ($.map(data, function(v,i){
                        return {
                            label: v.MainName,
                            value: v.MainItemID

                        }}))
                });
            }
        });
  • 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-06-17T17:05:41+00:00Added an answer on June 17, 2026 at 5:05 pm

    You need to change the success callback to

    response($.map(data, function(v,i){
        return {
                    label: v.MainName,
                    value: v.MainItemID
                   };
    }));
    

    Fiddle.

    The jQuery.map helps to Translate all items in an array or object to new array of items.

    Update: Add Filter

    $("#mainIngredientAutoComplete").autocomplete({
        source: function (request, response) {
            var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
            $.ajax({
                url: "../api/IngredientChoices",
                dataType: "json",
                success: function (data) {
                    response($.map(data, function(v,i){
                        var text = v.MainName;
                        if ( text && ( !request.term || matcher.test(text) ) ) {
                            return {
                                    label: v.MainName,
                                    value: v.MainItemID
                                   };
                        }
                    }));
                }
            });
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to setup an autocomplete field. I'v read the JQuery UI documentation,
I am trying to set up jQuery autocomplete in Rails 3.2.0. I have it
I'm trying to setup a select dropdown from which, using jQuery, each option will
I have been trying to get a simple example of the jquery-ui autocomplete to
I have been trying to setup custom ajaxTransports for jQuery to short-circuit some workflows
I am trying to setup a cascading dropdown with python/jquery/ajax. The first dropdown is
OK, what I'm trying to do here is to have jQuery UI update the
I have been trying to get a simple example of the jquery-ui autocomplete to
I am trying to setup jQuery rows, with add/remove row functionality. I got started
I'm trying to setup PhotoSwipe (http://www.photoswipe.com/) which is a photo gallery jquery plugin which

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.