2

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).

1
  • Did you try passing a JSON stringified array? Commented Jan 13, 2014 at 12:03

2 Answers 2

0

I know it's old - but if anyone comes across this, here's what I did to solve this issue when I had problems using $.post - basically use $.ajax and ensure you have a 'success' function

$.ajax({
    type:       'POST',
    url:        url,
    dataType:   'json',
    data:       data,
    success:    mySuccessFunc,
    error:      myErrorFunc
});
Sign up to request clarification or add additional context in comments.

Comments

0

The problem may be occurs on function call recursively. Please check the result array length carefully i think the for loop continues push the string .

Please go through the link : jQuery - Uncaught RangeError: Maximum call stack size exceeded

please off the event and continue please try the sample code add in your first line before on the event

$('#jqxTree').off('select');

2 Comments

The arrays I am working with don't exceed the length of 4, usually they are even shorter. I checked them in the debugger, their length is correct.
Not sure I got you right now... I just added the off-line before the first line of my snippet above and left everything else untouched. Error remains.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.