On my web site I use a jqxTree from http://www.jqwidgets.com. You can find the API here, if you want to look something up: http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxtree/jquery-tree-api.htm
This tree provides a select-event handler in that I'm building a path from the root item down to the selected element. Then I want to pass that path via a JQuery $.post to my backend server implementation.
$('#jqxTree').on('select',function (event) {
var item = $('#jqxTree').jqxTree('getSelectedItem');
var cur = $('#jqxTree').jqxTree('getItem', item.parentElement);
var result = [item];
while (cur != null) {
result.unshift(cur);
cur = $('#jqxTree').jqxTree('getItem', cur.parentElement);
}
// this loop is mainly for testing purposes
var str = "";
for (var i = 0; i < result.length; i++) {
str += result[i].label + " > ";
}
alert("The selected path is " + str);
$.post("TreeSelectHandler", {
'path': result
});
});
Executing this code leads to a perfectly fine alert-output, so the code works well. But JQuery logs an RangeError: Maximum call stack size exceeded when I am trying to execute the post request.
Sending str instead of result as post parameter works fine, but I would prefer being able to directly pass the array. What am I doing wrong or did I stumble upon a bug?
I'm using JQuery 1.10.2, the error occurs at least in current versions of Chrome and Firefox.
Update
Trying to stringify the array, using the following code:
var jsonres = JSON.stringify(result);
$.post("TreeSelectHandler", {
'path': jsonres
}, null, 'text');
Fails with:
Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.
in the first line (stringify).