简体   繁体   English

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

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

I'm having an issue while populating a FancyTree tree via the ajax call option. 通过ajax调用选项填充FancyTree树时出现问题。 The source of the page and the tree data is PL/SQL package from an Oracle 10 database. 页面和树数据的源是来自Oracle 10数据库的PL / SQL包。 I call tree_test.show_page and it uses htp.p to display this simple test page (script links removed for clarity): 我调用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>

The tree doesn't display, but in the Chrome debugger I can see where the call to test_tree.get_tree was successfully made. 该树未显示,但是在Chrome调试器中,我可以看到成功调用test_tree.get_tree I'm assuming that the issue is that the string response is not being seen as JSON data. 我假设问题是字符串响应没有被视为JSON数据。 I know the data is good because if I add var treeData = <JSON data here> and change the FancyTree source parameter to source: treeData , it works fine. 我知道数据是很好的,因为如果我添加var treeData = <JSON data here>并将FancyTree source参数更改为source: treeData ,则可以正常工作。 And the tree data is supplied by the same PL/SQL procedure regardless of which way the source parameter is configured. 而且,树数据是由相同的PL / SQL过程提供的,而与配置source参数的方式无关。

In the Chrome debugger, it shows the content-type of the response as text/html (see edit below). 在Chrome调试器中,它将响应的内容类型显示为 text / html (请参见下面的编辑)。 I've tried various values for the dataType parameter ("json", "html json", "text json", "html text json", etc) with no success. 我尝试了dataType参数的各种值(“ json”,“ html json”,“ text json”,“ html text json”等),但均未成功。

Am I missing something obvious?? 我缺少明显的东西吗?

Below is the sample JSON data: 以下是样本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"}]}]}]

Edit: 编辑:
By suggestion of Yogi, I added owa_util.MIME_HEADER('application/json', true) to the tree_test.get_tree procedure and now the content-type of the response shows as application/json in Chrome's debugger. 根据Yogi的建议,我将owa_util.MIME_HEADER('application/json', true)tree_test.get_tree过程中,现在响应的内容类型在Chrome的调试器中显示为application/json But the tree still doesn't get populated with data. 但是树仍然没有填充数据。

This is not valid JSON data, but a JavaScript object dump: 不是有效的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"}]}]}]

it should be 它应该是

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

See http://json.org/ http://json.org/

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

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