I want to pass the data from a fancytree to a generic handler so that I can save it for future use.
If I use this code:
function SaveTree() {
var tree = $('#TopTree').fancytree("getTree");
$.ajax({
cache: false,
url: "SaveTree.ashx",
data: { 'treeData': tree },
contentType: "application/json; charset=utf-8"
});
}
Then I get the following error from jquery.js:
JavaScript runtime error: Argument not optional
I have also tried:
var tree = $('#TopTree').fancytree("getTree").rootNode.children;
This gives the same error. I understand it is because 'tree' is not JSON. How can I convert the data to a JSON object?
EDIT:
If I use this code:
function SaveTree() {
var data = [];
var tree = $('#TopTree').fancytree("getTree").rootNode.children;
for (var i = 0; i < tree.length; i++) {
data.push(tree[i].title)
}
data = JSON.parse(JSON.stringify(data))
$.ajax({
cache: false,
url: "SaveTree.ashx",
data: { 'treeData': data },
contentType: "application/json; charset=utf-8"
});
}
I can get it to accomplish what I need, but is there not a built-in function for this in fancytree?