Hi, I am trying to load JSON from the server through an AJAX call but i keep getting this error '
Uncaught Error: Syntax error, unrecognized expression: "my json from the server" the JSON being returned is being converted to the pattern that jstree states, i.e,
[
{ "id": "ajson2", "parent": "#", "text": "Root node 2" },
{ "id": "ajson3", "parent": "ajson2", "text": "Child 1" },
{ "id": "ajson1", "parent": "#", "text": "Simple root node" },
]
I am using jstree version 3.0.2, Jquery 1.11.1 and angularjs 1.0.6.
Below is the code i am using to do the conversion and load the tree. any help would be much appreciated
$(document).ready(function () {
var treedata = [];
$.ajax({
url: "my JSON url",
type: "GET",
dataType: "JSON",
headers:
{
"I attach an API key here",
"accept": "application/json; charset=utf-8",
"Content-Type": "application/json"
},
success: function (data, txtStatus, request) {
return CallAjaxSuccess(data, txtStatus, request);
},
error: function (request, txtStatus, err) {
var errorData = [];
return errorData;
}
});
function CallAjaxSuccess(data, txtStatus, request) {
if (request.status === 200) {
if (data) {
data.folders.forEach(function (folder) {
var string;
if (folder.parent == '0@') { //Root folders in my JSON from the server has id: 0@
string = '#';
} else {
string = folder.parent;
}
var nodes = {
parent: string
}
treedata.push(nodes);
return treedata;
});
}
}
$('#jstree1').jstree({
'plugins': ["wholerow"],
'core': {
'data': JSON.stringify(treedata) //If i leave out the JSON.stringify i get error: Uncaught TypeError: Cannot read property 'children' of undefined
}
});
}
});