【发布时间】:2011-07-15 03:09:59
【问题描述】:
我想进行 ajax 调用以获取 results 节点的数据。在我的示例代码(see here) 中,进行了 ajax 调用,但服务器没有返回任何内容(使用 firebug 测试)但是如果我在 Web 浏览器中使用相同的 url,我可以保存 json 文件。
我的问题是:
- 如何使 ajax 调用工作,以便返回值显示在 jsTree 中?它工作得很好here - 搜索
Using both the data & ajax config options - 如何传递ajax调用参数
- 一个是父/父名称(basics 用于第一个结果节点)
- 第二个是父节点的名称(login 是第一个结果节点)
在下面查看我的代码或使用fiddle
<html>
<head>
<title>jsTree & ajax</title>
<script type="text/javascript" src="http://static.jstree.com/v.1.0pre/jquery.js"></script>
<script type="text/javascript" src="http://static.jstree.com/v.1.0pre/_docs/syntax/!script.js"></script>
<script type="text/javascript" src="http://static.jstree.com/v.1.0pre/jquery.cookie.js"></script>
<script type="text/javascript" src="http://static.jstree.com/v.1.0pre/jquery.hotkeys.js"></script>
<script type="text/javascript" src="http://static.jstree.com/v.1.0pre/jquery.jstree.js"></script>
<script type='text/javascript'>
data = [
{
"data" : "Basics",
"state" : "closed",
"children" : [ {
"data" : "login",
"state" : "closed",
"children" : [ "login", {"data" : "results", "state" : "closed"} ]
} ,
{
"data" : "Basics",
"state" : "closed",
"children" : [ "login", "something",{"data" : "results", "state" : "closed"} ]
} ]
},
{
"data" : "All",
"state" : "closed",
"children" : [ {
"data" : "AddCustomer",
"state" : "closed",
"children" : [ "login","Add", {"data" : "results", "state" : "closed"} ]
} ]
}
]
$(function () {
$("#jstree").jstree({
"json_data" : {
"data" : data ,
"ajax" : { "url" : "http://www.jstree.com/static/v.1.0pre/_docs/_json_data.json" }
},
"plugins" : [ "themes", "json_data" ]
});
});
</script>
</head>
<body>
<div id="jstree"></div>
</body>
</html>
更新 1
即使我将示例代码从 jstree.com 复制到 jsfiddle,它也不起作用。我想我在某个地方遗漏了一些东西......
【问题讨论】:
标签: jquery-plugins jquery jstree