0

我在通过 ajax 调用选项填充 FancyTree 树时遇到问题。页面和树数据的来源是来自 Oracle 10 数据库的 PL/SQL 包。我打电话tree_test.show_page,它htp.p用来显示这个简单的测试页面(为了清楚起见,删除了脚本链接):

<html>
<head>
<title>Tree Testing</title>
<script type="text/javascript">

  $(function() {
    // Create the tree inside the <div id="tree"> element.
    $("#tree").fancytree({
      checkbox: true, // Show checkboxes.
      debugLevel: 2,  // 0:quiet, 1:normal, 2:debug
      selectMode: 3,  // 1:single, 2:multi, 3:multi-hier
      source: {
        url: "tree_test.get_tree",
        dataType: "json",
        cache: true
      }
    }); // end of fancytree def
  });
</script>
</head>
<body>
<p>Tree structure:</p>
<div id="tree"></div>
</body>
</html>

树没有显示,但在 Chrome 调试器中,我可以看到test_tree.get_tree成功调用的位置。我假设问题是字符串响应没有被视为 JSON 数据。我知道数据很好,因为如果我添加var treeData = <JSON data here>FancyTreesource参数并将其更改为source: treeData,它可以正常工作。source并且无论参数的配置方式如何,树数据都由相同的 PL/SQL 过程提供。

在 Chrome 调试器中,它将响应的内容类型显示为text/html(请参阅下面的编辑)。我尝试了dataType参数的各种值(“json”、“html json”、“text json”、“html text json”等),但没有成功。

我错过了一些明显的东西吗?

以下是示例 JSON 数据:

[{title: "Root Group", key: "g0", folder: true, expanded: true, children: [{title: "Group 1", key: "g1", folder: true, expanded: true, children: [{title: "Node 1", key: "141", tooltip: "Node 1"},{title: "Node 2", key: "82", tooltip: "Node 2"}]},{title: "Group 2", key: "g2", folder: true, expanded: true, children: [{title: "Node 3", key: "91", tooltip: "Node 3"}]}]}]

编辑:
根据 Yogi 的建议,我添加owa_util.MIME_HEADER('application/json', true)tree_test.get_tree程序中,现在响应的内容类型显示为application/jsonChrome 的调试器中的内容。但是树仍然没有填充数据。

4

1 回答 1

0

不是有效的 JSON 数据,而是 JavaScript 对象转储:

[{title: "Root Group", key: "g0", folder: true, expanded: true, children: [{title: "Group 1", key: "g1", folder: true, expanded: true, children: [{title: "Node 1", key: "141", tooltip: "Node 1"},{title: "Node 2", key: "82", tooltip: "Node 2"}]},{title: "Group 2", key: "g2", folder: true, expanded: true, children: [{title: "Node 3", key: "91", tooltip: "Node 3"}]}]}]

它应该是

[{"title": "Root Group", "key": "g0", "folder": true, ...

http://json.org/

于 2014-07-10T17:04:39.180 回答