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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:50:33+00:00 2026-05-20T05:50:33+00:00

I’m having trouble in parsing my JSON data in jQuery autocomplete. My JSON comes

  • 0

I’m having trouble in parsing my JSON data in jQuery autocomplete. My JSON comes from this code:

<cfset theQ = lcase(q)>

<cfquery datasource="#source#" name="qry" maxrows="20">
    select top 10 lastname
    from info
    where
    lower(lastname) like '#theQ#%'
    order by lastname
</cfquery>

<!---
Before we can serialize the query, we need to convert
it to an array of structs.
--->
<cfset rows = [] />

<!--- Loop over the query to convert it. --->
<cfloop query="qry">

<!--- Create a row struct. --->
<cfset row = {} />

<!--- Add each column to our struct. --->
<cfloop
index="column"
list="#qry.columnList#"
delimiters=",">

<cfset row[ column ] = qry[ column ][ qry.currentRow ] />

</cfloop>

<!--- Append the row struct to the row array. --->
<cfset arrayAppend( rows, row ) />

</cfloop>

<!---
Now that we have converted our query to an
array of structs, we can serialize it using the
serializeJSON() method.
--->
<cfset serializedQuery = serializeJSON( rows ) />
<cfoutput>#serializedQuery#</cfoutput>

I converted my query into array of structures and then serialized it to JSON. Now, parsing this JSON in jQuery autocomplete does not work. The data I get looks like this:

[{"lastname":"abc"},{"lastname":"def"},{"lastname":"ghi"}]

Here is the code for autocomplete:

$(document).ready(function() {
    $("#name").autocomplete("data/name.cfm",{
        minChars:1,
        delay:10,
        autoFill:false,
        matchSubset:false,
        matchContains:1,
        cacheLength:10,
        selectOnly:1,
        dataType: 'json',

        parse: function(data) {
            var parsed = [];
            var dataParsed = $.parseJSON(data);
                for (var i = 0; i < dataParsed.length; i++) {
                parsed[parsed.length] = {
                data: dataParsed[i],
                value: dataParsed[i].lastname,
                result: dataParsed[i].lastname
                };
            }

            return parsed;
        },
        formatItem: function(item) {
            return item;
        }

    });

When I type in the text field, I get the whole JSON string as the search result. I’ve looked into other codes for parsing but still I can’t get it working. Any help? Thanks.

References:
Simon Whatley for autocomplete;
Ben Nadel for query to array of structs and serialize to json

  • 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-20T05:50:33+00:00Added an answer on May 20, 2026 at 5:50 am

    One problem is that in your for loop you are iterating up to data.length when you should be iterating up to dataParsed.length

    If you are using the Simon Whatley autocomplete plug-in, according to the demo on his website, the plugin simply expected the autocomplete results to be on individual lines, e.g:

    abc
    def
    ghi
    

    So you should get rid of the parse function you provide in jquery, and modify your coldfusion script to return one name per line i.e. abc\ndef\n... No need to use json or anything else. (at least thats how this demo on his website works http://www.simonwhatley.co.uk/examples/autocomplete/jquery/data/country.php)

    Just to confirm, you should add an alert('aaa') to the inside of your parse() function, I bet you will see that it is never being called.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.