ajax json string returning undefined

1.2k views Asked by At

I am using a library of thejit.org, and the graph is space tree.

st.onClick(node.id, {
   Move: {
   enable: true,
   offsetX: 30,
   offsetY: 5
   },
   onComplete: function() {
    $.ajax({

     type: "POST",
    url: "Home",
    data: "node="+node.id,
    dataType: "json",
    success: function(data) {

st.loadJSON(data.d); //error
st.compute();
st.geom.translate(new $jit.Complex(-200, 0), "current");
st.onClick(st.root);
st.refresh();
}

I am trying to regenerate the graph with a new json once a node is clicked. In the onclick function I am making an ajax call, the data if printed out is correct. even if iI use the data printed to decalre a varialbe and use it. graphs is generated,but when I use it with ajax I get undefined.

Edit-1

JSONObject obj = new JSONObject();

response.setContentType("application/json; charset=utf-8");

PrintWriter out = response.getWriter();

String data=    
"{id:\"90\",name:\"s\",data:{},children:[{ id:\"2\",name:\"2\",data:{},children:[{ id:\"3\",name:\"3\",data:{},children:[]},{ id:\"1265\",name:\"1265\",data:{},children:[]}]},{ id:\"8\",name:\"8\",data:{},children:[{ id:\"9\",name:\"9\",data:{},children:[]},{ id:\"12\",name:\"12\",data:{},children:[]}]}]};";

obj.put("d", data);

out.print(obj);

out.flush();
0

There are 0 answers