繁体   English   中英

如何使来自pl / sql的字符串在FancyTree的ajax调用中被视为json响应?

[英]How to make string from pl/sql be seen as json response in an ajax call from FancyTree?

通过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>并将FancyTree source参数更改为source: treeData ,则可以正常工作。 而且,树数据是由相同的PL / SQL过程提供的,而与配置source参数的方式无关。

在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过程中,现在响应的内容类型在Chrome的调试器中显示为application/json 但是树仍然没有填充数据。

不是有效的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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM