jstree dynamic JSON data from django
        Posted  
        
            by danspants
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by danspants
        
        
        
        Published on 2010-06-15T23:12:44Z
        Indexed on 
            2010/06/15
            23:22 UTC
        
        
        Read the original article
        Hit count: 1324
        
I'm trying to set up jsTree to dynamically accept JSON data from django.
This is the test data i have django returning to jstree:
result=[{ "data" : "A node", "children" : [ { "data" : "Only child", "state" : "closed" } ], "state" : "open" },"Ajax node"]
response=HttpResponse(content=result,mimetype="application/json")
this is the jstree code I'm using:
jQuery("#demo1").jstree({   
           "json_data" : {  
             "ajax" : {  
                "url" : "/dirlist",  
                "data" : function (n) {   
                    return { id : n.attr ? n.attr("id") : 0 };   
                },
                 error: function(e){alert(e);}
             }  
         },  
        "plugins" : [ "themes","json_data"]
     });
All I get is the ajax loading symbol, the ajax error response is also triggered and it alerts "undefined". I've also tried simpleJson encoding in django but with the same result.
If I change the url so that it is receiving a JSON file with identical data, it works as expected.
Any ideas on what the issue might be?
© Stack Overflow or respective owner