SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JQuery "Unrecognized expression" for JSON

    Hi!

    I have a jstree plugin which I am trying to pass data from a Java servlet. I am using JQuery 1.10.2.

    My javascript:

    Code JavaScript:
    $('#treeFolderName').jstree({
                        "core" : {                      
                          'data' : {
                            'url' : function (node) {
                                return node.id === '#' ?
                                  '../MediaServletTree' : '../MediaServletTree';
                                  //'ajax_demo_children.json' : 'ajax_demo_children.json';
                            },
                            'data' : function (node) {
                              return { 
                                  'id' : node.id
                              };
                            }
                          }
                        }
                 });

    My code in Java for MediaServletTree:

    Code Java:
    JSONObject jsonObj = new JSONObject();
    jsonObj.put("id", "demo_child_1");
    jsonObj.put("text", "Child 1");
    out.print(jsonObj);

    which results in:

    {"id":"demo_child_1","text":"Child 1"}

    If I use Java's 'MediaServletTree', I get 'Uncaught Error: Syntax error, unrecognized expression: {"id":"demo_child_1","text":"Child 1"}'.

    If I copy the JSON and put inside a text file and run ajax_demo_children.json. No problem.

    How to I resolve unrecognized expression?

    Please help. Thanks.

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found the error: set this in Java:

    Code Java:
    response.setContentType("text/json;charset=UTF-8");


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •