jquery - jsTree JSON parse issue -


i use jstree plugin display department stricture. serverside (asp.net 3.5) works , json object.

but when try:

$(document).ready(function () {     $('#btntst').click(function () {         $('#maindiv').html('wait 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 1 node json string in it.
json-string, returned webmethod is:

{   'data': 'department001',   'attr': {     'id': 'nodeid1773'   },   'children': [    ] }, {   'data': 'department001',   'attr': {     'id': 'nodeid1779'   },   'children': [    ] } 

if copy-paste string to:

"json_data": {"data" : [...] } 

i correct result. pleas help, can't doing wrong.

your script looking json object of type json_data normal response data. see if these changes work:

$(document).ready(function () {     $('#btntst').click(function () {         $('#maindiv').html('wait 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         });     });  }); 

Comments