2

I've been trying for hours and can't get it to work. I am trying to initialize Fancytree with ajax. This is what I've got so far.

$(function(){
    $("#tree").fancytree({
               initAjax: {url: "/ajaxData.do",
               data: "action=buyclassification",
               }
        });
    });

It looks simple but I can't figure out what I am doing wrong.

Svedr
  • 589
  • 2
  • 6
  • 21

1 Answers1

3

Looking at the docs the data parameter should be in JSON. Try:

$(function(){
$("#tree").fancytree({
           initAjax:{ 
               url: "/ajaxData.do",
               data: {action: "buyclassification"}
           }
    });
});
Daniel Waghorn
  • 2,997
  • 2
  • 20
  • 33
  • Thanks daniel for your input! Still doesn't work though :/ EDIT: Nevermind, it's working. Thanks a lot. It was just a matter of swapping `initAjax`with `source` – Svedr Jul 04 '15 at 22:36
  • No problem, I'd have a look at the data values you're feeding to it to make sure that they're what it's expecting since the examples I looked at seemed to supply more values. Also is your 'ajaxData.do' file in your document root? Just asking incase you're inadvertently targeting the url parameter with an absolute path rather than a relative path. – Daniel Waghorn Jul 04 '15 at 22:40
  • one more thing. I am trying to append children to these elements `lazyLoad: function(event, data) { var nodeID = node.key; // Issue an ajax request to load child nodes data.result = { url: "/ajaxData.do", data: {action: "buyclassification" + "&parrentID="+ nodeID}, } }`. The documentation for this is on the end of the site https://github.com/mar10/fancytree/wiki/WhatsNew. This Ajax is killing me :D – Svedr Jul 04 '15 at 23:11
  • I can't see any significant problems, although is 'parrentID' spelled correctly to match the parameter in your serverside code? Other than that are any errors displayed in the console? You can debug AJAX and have a look at the response data in Chrome easily. Have a look at [this post](http://stackoverflow.com/a/3206882/5065008) which details how to do this. – Daniel Waghorn Jul 04 '15 at 23:23