user275074
user275074

Reputation:

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:-

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: -

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

Upvotes: 1

Views: 198

Answers (1)

Nick Craver
Nick Craver

Reputation: 630439

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:

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

Upvotes: 4

Related Questions