I am trying to pass JSON data to a jstree object from an external file. The code snippet I have does not seem to be working properly.
<script>
$.jstree.defaults.core.themes.responsive = true;
$('#frmt').jstree({
plugins: ["checkbox", "types"],
"json_data":{
"ajax" : {
"url" : "D:\p\web\nodes.json" // the URL to fetch the data. Use relative url if required
}
},
"types": {
"file": {
"icon": "jstree-file"
}
}
});
</script>
Here is my nodes.json file:
[
{
"id": "ajson1",
"parent": "#",
"text": "Simple root node"
},
{
"id": "ajson2",
"parent": "#",
"text": "Root node 2"
}, {
"id": "ajson3",
"parent": "ajson2",
"text": "Child 1"
}, {
"id": "ajson4",
"parent": "ajson2",
"text": "Child 2"
}
]
Manually inserting this data into JavaScript works fine, but when assigning the path of nodes.json to an external file, it doesn't seem to work as expected.