Я хочу сделать вызов ajax, чтобы получить данные для узлов results
. В моем примере кода (см. здесь) выполняется вызов ajax, но сервер ничего не возвращает (проверено с помощью firebug) Но если я использую тот же URL-адрес в веб-браузере, я могу сохранить файл json.
Мои вопросы:
- как заставить работать вызов ajax, чтобы возвращаемые значения отображались в jsTree? Это прекрасно работает здесь — найдите
Using both the data & ajax config options
- how to pass the ajax call parameters
- one would be the parent/parent name ( basics for the first results node )
- вторым будет имя родительского узла ( логин для первого узла результатов)
Посмотрите мой код ниже или используйте скрипту.
<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, он не будет работать. Я видимо что-то где-то упускаю....