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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:19:53+00:00 2026-05-28T16:19:53+00:00

How can I use this json data as data source of jquery autocomplete? [{uid:123,UserName:xxx},{uid:124,UserName:yyy}]

  • 0

How can I use this json data as data source of jquery autocomplete?

[{"uid":"123","UserName":"xxx"},{"uid":"124","UserName":"yyy"}]


<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="jquery.ui.core.js" type="text/javascript"></script>
<script src="jquery.ui.position.js" type="text/javascript"></script>
<script src="jquery.ui.widget.js" type="text/javascript"></script>
<script src="jquery.ui.autocomplete.js" type="text/javascript"></script>

<input name="Txt1" type="text" id="Txt1">

<script language="javascript" type="text/javascript">
$("#Txt1").autocomplete(
{
  source:[{"uid":"123","UserName":"xxx"},{"uid":"124","UserName":"yyy"}]
}
)
</script>
  • 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-28T16:19:55+00:00Added an answer on May 28, 2026 at 4:19 pm

    I have found the best practice with custom returned values is to create a parse function. This allows you to do what you want with your returned JSON. In this sample code, I do not address the ajax call, but I can add that as well if you need. jQuery UI Autocomplete looks for a label and a value entity. You can put either of those in as you see fit, or even do some custom stuff if needed.

    var myStuff = [{
        "uid": "123",
        "UserName": "xxx"},
    {
        "uid": "124",
        "UserName": "yyy"}];
    
    function imAutocompleteJSONParse(data) {
        var rows = [];
        var rowData = null;
        var dataLength = data.length;
        for (var i = 0; i < dataLength; i++) {
            rowData = data[i];
            rows[i] = {
                label: rowData.UserName,
                value: rowData.UserName
            };
        }
        return rows;
    }
    
    $("#Txt1").autocomplete({
        source: function(request, response) {
            var rows = imAutocompleteJSONParse(myStuff);
            return response(rows);
        },
        minLength: 2
    });
    

    For clarity sake, I put this in a fiddle page so you can see it working: http://jsfiddle.net/MarkSchultheiss/TRKeE/

    NOW, as I suspect YOU want to do some custom/different stuff with the results, I have created this custom example on how to work with custom values: http://jsfiddle.net/MarkSchultheiss/TRKeE/2/

    The difference is I changed the parse function and added a new autocomplete option.

    var myStuff = [{
        "uid": "123",
        "UserName": "xxx"},
    {
        "uid": "124",
        "UserName": "yyy"}];
    
    function imAutocompleteJSONParse(data) {
        var rows = [];
        var rowData = null;
        var dataLength = data.length;
        for (var i = 0; i < dataLength; i++) {
            rowData = data[i];
            rows[i] = {
                uid: rowData.uid,
                UserName: rowData.UserName,
                label: rowData.UserName,
                value: rowData.uid
            };
        }
        return rows;
    }
    
    $("#Txt1").autocomplete({
        source: function(request, response) {
            var rows = imAutocompleteJSONParse(myStuff);
            return response(rows);
        },
        select: function(event, ui) {
            var hasValue = (ui.item.value != undefined && ui.item.value != "" && ui.item.value != null);
            if (hasValue) {
                var focusedElement = $(this);
                focusedElement.val(ui.item.label);
                $('#labelResult').text(ui.item.label);
                $('#valueResult').text(ui.item.label);
                $('#customResult').text(ui.item.uid + ":" + ui.item.UserName);
    
                return false;
            }
            else {
                return false;
            }
        },
        minLength: 2
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When working with JSON, I can use NuGet to add JSON.Net and this allows
I try to use autocomplete jquery-ui script, but from the documentation it's explain that
How can I use the selected item from a jQuery-ui autocomplete in a further
I can use this maven plugin maven-jaxb-plugin to generate Java Classes from XSD file.
Right now I can use this URL to request a Google Static Maps image
I know I can use this way to find the most frequent element in
Simple. If I use: public void Add(params int[] values) Then I can use this
I am wondering whether I can use the this keyword inside a C# lambda,
When you have an object instance in C#, you can use the this keyword
I don't know if I can use regex for this, but I want to

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.