fancytree单击上发布ajax

I'm using fancytree to create a tree structure from mysql data source...

https://github.com/mar10/fancytree/wiki

I want to update the db on change of this structure and this is my code

$("#tree").on("fancytreeclick", function(event, data){

  var nodes = $('#tree').fancytree("getTree").getSelectedNodes();
  console.log(nodes);

  $.ajax({
    type : 'POST',
    url  : 'call/myclass.php',
    data : {
      selected : nodes,
      tipo : "update",
    },
    success :  function(data) {
      // nothing
    },

    error: function(data) { 
      console.log(data);
    },
  });

});

but I'm getting this error

Uncaught RangeError: Maximum call stack size exceeded
at Function.isArray (<anonymous>)

Why this?

The method

tree.getSelectedNodes()

returns an array of FancytreeNode objects. You need to convert this to plain objects, so the $.ajax function can serialize it.

For example iterate over the Array and use node.toDict():

var selNodes = $("#tree").fancytree("getTree").getSelectedNodes();
var selData = $.map(selNodes, function(n){
  return n.toDict();
});