[英]jsTree JSON parse issue
我使用JSTree插件顯示部門限制。 Serverside(asp.net 3.5)運行良好,並且我得到了JSON對象。
但是當我嘗試:
$(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
});
});
});
我只有一個帶有所有JSON字符串的節點。
JSON字符串,由webmethod返回:
{
'data': 'department001',
'attr': {
'id': 'nodeid1773'
},
'children': [
]
},
{
'data': 'department001',
'attr': {
'id': 'nodeid1779'
},
'children': [
]
}
如果我將此字符串復制粘貼到:
"json_data": {"data" : [...] }
我得到正確的結果。 請幫助,不能理解我在做什么錯。
您的腳本正在尋找json_data
類型的JSON對象,但通常的響應只是data
。 查看這些更改是否有效:
$(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.