It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Yahoo YUI autocomplete - JSON & "invalid label"

Yahoo YUI autocomplete - JSON & "invalid label"

Postby ablemorghon on Thu Aug 21, 2008 7:20 am

Hello:

I'm experiencing a problem with the following script using Yahoo's YUI 2.5.2:

Code: Select all
  <div class="yui-skin-sam">
    <div id="myAutoComplete" style="margin-bottom:3em; width:25em;">
      <input id="keywords" type="text">
      <div id="autoCompleteContainer"></div>
    </div>

  <script type="text/javascript">
  <!--
    var dataSource = new YAHOO.widget.DS_ScriptNode("http://localhost:8080/?action=autocomplete", ["keywords", "keyword"]);
    var autoComplete = new YAHOO.widget.AutoComplete("keywords", "autoCompleteContainer", dataSource);
  //-->
  </script>

  </div>


The service that is called by the DS_ScriptNode widget is written in java and uses json-lib-2.2.2. It returns the following:

{"keywords":[{"keyword":"java"},{"keyword":"jboss"}]}

Upon typing in the inputfield, firebug shows me the following error:

invalid label

Naturally, I've searched the web for this error and it is due to the way the json-tree is evaluated by javascript. For it to function properly, the json-tree must be enclosed in paranthesis, like so:

({"keywords":[{"keyword":"java"},{"keyword":"jboss"}]})

However, it seems to me (as far as I have been able to determine som far), that all evaluations done by the YUI-library enclose the json-tree like that. So, does anyone have any ideas where I could look next?

All help will be much appreciated :)
ablemorghon
 
Posts: 2
Joined: Thu Aug 21, 2008 6:59 am

[SOLVED] Yahoo YUI autocomplete - JSON & "invalid l

Postby ablemorghon on Thu Aug 21, 2008 1:20 pm

Hey:

I managed to solve this issue :) The service that returns the json must handle a "callback" parameter and wrap the json in it if it's present, i.e.

YAHOO.widget.DS_ScriptNode.callbacks[1]({"keywords":[{"keyword":"java"},{"keyword":"jboss"}]})

Hope this can be of help to others.
ablemorghon
 
Posts: 2
Joined: Thu Aug 21, 2008 6:59 am

Re: Yahoo YUI autocomplete - JSON & "invalid label"

Postby abhatnager on Fri Oct 30, 2009 7:24 pm

Hi There,

I am using SOlr.

Please explain How did u solve this problem "invalid label"

Ankit
abhatnager
 
Posts: 1
Joined: Fri Oct 30, 2009 7:22 pm


Who is online

Users browsing this forum: No registered users and 2 guests