簡體   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