$.getJson(url,data,callback)回调函数不执行的问题
发布时间:2020-12-16 19:44:31 所属栏目:百科 来源:网络整理
导读:页面调用如下方法 jsonTree(); function jsonTree(){console.log("jsonTree is begin")$.getJSON(ctx+"/node/treeNodesJson.js",function(json){console.log("json data")console.log(json)})console.log("jsonTree is end")} XHR 中显示json数据的文件也已
页面调用如下方法 jsonTree(); function jsonTree(){ console.log("jsonTree is begin") $.getJSON(ctx+"/node/treeNodesJson.js",function(json){ console.log("json data") console.log(json) }) console.log("jsonTree is end") } XHR 中显示json数据的文件也已经加载,但是回调函数就是不执行
最后发现是json的数据格式不正确--必须严格遵守json格式要求 var zNodes =[//不能写等号前的东西 {id:5,pId:0,name:"组合功能 演示",open:false},{id:501,pId:5,name:"冻结根节点",file:"super/oneroot"},{id:502,name:"单击展开/折叠节点",file:"super/oneclick"},{id:503,name:"保持展开单一路径",file:"super/singlepath"},{id:504,name:"添加 自定义控件",file:"super/diydom"},{id:505,name:"checkbox / radio 共存",file:"super/checkbox_radio"},{id:506,name:"左侧菜单",file:"super/left_menu","children":[ {"id":513,"name":"资源1","num":0,"open":false,"pId":1},{"id":514,"name":"资源2",//这里的逗号不能有 ] },{id:513,name:"OutLook 样式的左侧菜单",file:"super/left_menuForOutLook"},{id:507,name:"下拉菜单",file:"super/select_menu"},//不能有逗号 ];//不能有分号 1.json必须是对象或者数组 2.不能有多余的东西,严格的json格式 3.id、pid、name等必须加双引号 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |