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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:31:03+00:00 2026-06-03T00:31:03+00:00

I am parsing the string returned from Cakephp 2.0 Controller.. My Autocomplete code is..

  • 0

I am parsing the string returned from Cakephp 2.0 Controller..

My Autocomplete code is..

jQuery("#name").autocomplete( '<?php echo HTTP_PATH.'/lensmaterials/getBrands'; ?>', {
    multiple: true,
    mustMatch: true,
    matchContains: true,
    autoFill: false,
    dataType: "json",
    parse: function(data) {
        return $.map(data, function(item) {
            return { data: item, value: item.label, result: item.label};
        });
    },
    formatItem: function(item) {
        return '<li>' + item.label + '</li>';
    }
});

I am getting list like Value, than undefined , than value than undefined.
Its ending me with error in firebug. If I select than value is not entered in my textbox.
I want the Value in beautiful way. That is Div showing list in ul, li…

My Controller code is..

public function getBrands(){
    $brandList = $this->Brand->find('list',array('fields'=>array('id','brand_name'),'order' => array('Brand.brand_name')));
    //pr($brandList); exit;
    foreach ($brandList as $key => $name) {
        $json_output[]['id'] = $key;
        $json_output[]['label'] = $name;
    }
    echo json_encode($json_output);
    $this->autoRender = false;
}

Returning JSON string is

 [{"id":1},{"label":"Bvlgari"},{"id":2},{"label":"Chanel"},{"id":7},{"label":"D & G"},{"id":8},{"label":"Dior"},{"id":10},{"label":"Emporio Armani"},{"id":11},{"label":"Fendi"},{"id":12},{"label":"Giorgio Armani"},{"id":13},{"label":"Gucci"},{"id":14},{"label":"Oakley"},{"id":15},{"label":"Oliver Peoples"},{"id":16},{"label":"Paul Smith"},{"id":4},{"label":"Polo Ralph Lauren"},{"id":18},{"label":"Prada"},{"id":19},{"label":"Prada Linea Rossa"},{"id":20},{"label":"Ray Ban"},{"id":21},{"label":"Tiffany"},{"id":3},{"label":"Tom Ford"}]

Final its not returning as I type. That is I have Chanel and if I type than unformatted and undefined never continue with my keyup. It remains constant.

  • 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-03T00:31:08+00:00Added an answer on June 3, 2026 at 12:31 am

    I think your data format is wrong. The id and label properties should be in the same object. Half of your objects don’t have a label property, so trying to access it will result in undefined (i.e. you get {data: {...}, value: undefined, result: undefined}).

    Change your generation process to:

    foreach ($brandList as $key => $name) {
        $json_output[] = array('id' => $key, 'label' => $name);
    }
    

    Then the output will be:

    [{"id":1,"label":"Bvlgari"},{"id":2,"label":"Chanel"},...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
I got a string from parsing a XML file which looks like this: Fri,
Not parsing the parameters in the beginning but parse the input string read from
From a SOAP webservice, a date field is returned as the string: 2010-12-21T08:55:17E-7+01:00 which
I have some Json being returned from facebook which I'm then parsing in to
Parsing the string message seems bad. Or was this exception not meant to be
strtok function uses a static variable for parsing the string into tokens. So this
I'm parsing a XML string into XMLDocument object. I want to search for a
I am parsing a long string of text and calculating the number of times
I'm doing some attribute parsing as a string, so I need to know how

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.