[英]jsTree JSON parse issue
I use JSTree plugin to display department stricture. 我使用JSTree插件显示部门限制。 Serverside (asp.net 3.5) works well and I get JSON object. Serverside(asp.net 3.5)运行良好,并且我得到了JSON对象。
But when I try: 但是当我尝试:
$(document).ready(function () {
$('#btntst').click(function () {
$('#mainDiv').html('wait for data');
$.ajax({
type: 'POST',
url: '_layouts/GridView/ApplicationPage1.aspx/getTable',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: "{}",
success: function (msg) {
$('#jsTreeContainer').jstree({
"json_data": {
"data": [msg.d]
}
, "plugins": ["themes", "json_data"]
});
}
, timeout: 60000
});
});
});
I get only one node with all JSON string in it. 我只有一个带有所有JSON字符串的节点。
JSON-string, returned by webmethod is: JSON字符串,由webmethod返回:
{
'data': 'department001',
'attr': {
'id': 'nodeid1773'
},
'children': [
]
},
{
'data': 'department001',
'attr': {
'id': 'nodeid1779'
},
'children': [
]
}
If I copy-paste this string to: 如果我将此字符串复制粘贴到:
"json_data": {"data" : [...] }
I get correct result. 我得到正确的结果。 Pleas help, can't get what am I doing wrong. 请帮助,不能理解我在做什么错。
Your script is looking for a JSON object of type json_data
but the normal response is only data
. 您的脚本正在寻找json_data
类型的JSON对象,但通常的响应只是data
。 See if these changes work: 查看这些更改是否有效:
$(document).ready(function () {
$('#btntst').click(function () {
$('#mainDiv').html('wait for data');
$.ajax({
type: 'POST',
url: '_layouts/GridView/ApplicationPage1.aspx/getTable',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: "{}",
success: function (msg) {
$('#jsTreeContainer').jstree({
"json_data": [msg.d],
"plugins": ["themes", "json_data"]
});
}
, timeout: 60000
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.