I use JSTree plugin to display department stricture. Serverside (asp.net 3.5) works well and I get JSON object.
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-string, returned by webmethod is:
{
'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
. 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
});
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.