$.getJson(url,data,callback)回调函数不执行的问题
2017-11-29 17:44
627 查看
页面调用如下方法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, pId:5, name:"单击展开/折叠节点", file:"super/oneclick"},
{id:503, pId:5, name:"保持展开单一路径", file:"super/singlepath"},
{id:504, pId:5, name:"添加 自定义控件", file:"super/diydom"},
{id:505, pId:5, name:"checkbox / radio 共存", file:"super/checkbox_radio"},
{id:506, pId:5, name:"左侧菜单", file:"super/left_menu",
"children":[
{"id":513,"name":"资源1","num":0,"open":false,"pId":1},
{"id":514,"name":"资源2","num":0,"open":false,"pId":1},//这里的逗号不能有
]
},
{id:513, pId:5, name:"OutLook 样式的左侧菜单", file:"super/left_menuForOutLook"},
{id:507, pId:5, name:"下拉菜单", file:"super/select_menu"},//不能有逗号
];//不能有分号
1.json必须是对象或者数组
2.不能有多余的东西,严格的json格式
3.id、pid、name等必须加双引号
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, pId:5, name:"单击展开/折叠节点", file:"super/oneclick"},
{id:503, pId:5, name:"保持展开单一路径", file:"super/singlepath"},
{id:504, pId:5, name:"添加 自定义控件", file:"super/diydom"},
{id:505, pId:5, name:"checkbox / radio 共存", file:"super/checkbox_radio"},
{id:506, pId:5, name:"左侧菜单", file:"super/left_menu",
"children":[
{"id":513,"name":"资源1","num":0,"open":false,"pId":1},
{"id":514,"name":"资源2","num":0,"open":false,"pId":1},//这里的逗号不能有
]
},
{id:513, pId:5, name:"OutLook 样式的左侧菜单", file:"super/left_menuForOutLook"},
{id:507, pId:5, name:"下拉菜单", file:"super/select_menu"},//不能有逗号
];//不能有分号
1.json必须是对象或者数组
2.不能有多余的东西,严格的json格式
3.id、pid、name等必须加双引号
相关文章推荐
- jQuery.getJSON(url, [data], [callback])[通过url,文件。txt,带参数三种方式](十三)
- 关于jquery中$.getJSON()不执行回调函数的问题。
- jQuery.getJSON( url [, data ] [, success ] ) 中的回调函数参数不执行
- jQuery.getJSON(url, [data], [callback])
- jQueryAjax请求-jQuery.getJSON(url, [data], [callback])
- jQuery.getJSON(url, [data], [callback])
- $.getJSON('url',function(data){}) 中回调函数不执行
- 日常问题记录--getJSON函数不执行回调函数的原因总结
- jQuery Ajax请求-jQuery.get(url, [data], [callback], [type])
- 同时执行多个$.getJSON() 数据混乱的问题的解决
- 关于js深入理解:json作为函数参数 类似于jQuery的post函数,具有url,data ,和回调函数
- $.getJSON(url,function success(){})回调函数不起作用
- Jquery之页面间大数据交换$.getJSON(url,parames,callback)
- $.getJSON(url, data, function(data){ })访问同步
- HTML自定义按钮上传图片并实现预览(同时解决getAsDataURL()弃用问题)
- jQuery.get(url,[data],[callback])
- getJson方法不执行回调函数解决
- jQuery.get(url,[data],[callback])的[data]的作用
- $.get( url, [data], [callback] )
- 遇到问题----- jsp中$.getJSON方法不调用回调函数