jstree AJAX不起作用,有一个语法错误:json的无法识别的表达式

qiw*_*ren 2 ajax jquery json jstree

我使用jstree API通过AJAX请求json数据,但它不起作用,它向我显示错误:

错误:语法错误,无法识别的表达式:{"results":[{"id":"a","parent":"b","text":"hello","icon":"something ......"} ,{"id":"b","parent":"#","text":"world","icon":"somethingelse ..."}}}

似乎json是正确的格式,但AJAX无法识别它.

我的AJAX代码是这样的:

$('#jstree').jstree({ 
  'core' : {
      'data' : {
          'url' : 'loadjsTree.php',
          'data' : function (node) {
              return { 'id' : node.id };
          }
      }, 
  }
});
Run Code Online (Sandbox Code Playgroud)

我确实喜欢API演示:链接到演示

为什么它不起作用?有人帮帮我吗?谢谢!

Joh*_*ohn 5

您是否尝试从对象中删除"结果"?

{"results":[{"id":"a","parent":"b","text":"hello","icon":"something ......"},{"id":"b ", "父": "#", "文": "世界", "图标": "somethingelse ..."}]}

[{"id":"a","parent":"b","text":"hello","icon":"something ......"},{"id":"b","parent" : "#", "文": "世界", "图标": "somethingelse ..."}]

jstree的JSON结构 - http://www.jstree.com/docs/json/

你也可以尝试添加'dataType':'JSON'......

'url' : 'loadjsTree.php',
'dataType': 'JSON',
'data' : function (node) {
return { 'id' : node.id };
}
Run Code Online (Sandbox Code Playgroud)

我读到它已经不再需要,但它帮助了我.