ajax json字符串返回未定义
我使用的是thejit.org的库,图是空间树。
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();
}
一旦节点被删除,我试图用新的 json 重新生成图表 点击。在 onclick 函数中,我正在进行 ajax 调用,数据如果 打印出来的是正确的。即使我使用打印的数据来贴花 varialbe 并使用它。图表是生成的,但是当我将它与ajax一起使用时我 变得未定义。
编辑-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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论