简体   繁体   English

jQuery JSON - 为什么我收到以下错误?

[英]jQuery JSON - why am I getting the following error?

When using: - 使用时: -

$.getJSON("admin.php?format=json", { module: "data", action: "allBusinessUnitsByClientName", clientname : $('#client').val() }, function(json) {
    $.each(json.items, function(i,item){
        alert(i);
    });
});

I get the following error in the Firebug console:- 我在Firebug控制台中收到以下错误: -

a is undefined
a))();else c.error("Invalid JSON: "+a)...f(d)if(i)for(f in a){if(b.apply(a[f],

The Json being returned is in the following format: - 返回的Json采用以下格式: -

{"550":"Test 1","547":"Test 2","549":"Test 3"}

You're getting this because json.items is undefined here, you just want json (your object being returned, which has no items property), like this: 你得到这个是因为json.items在这里是undefined ,你只需要json (你的对象被返回,没有items属性),如下所示:

$.getJSON("admin.php?format=json", { module: "data", action: "allBusinessUnitsByClientName", clientname : $('#client').val() }, function(json) {
    $.each(json, function(i,item){
        alert(i);
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM