Can't get jquery output my json object
I have the following code on my page. I expect a series of json objects to be returned from the person_output.aspx page, which is successful. However, when it comes to outputting content, I get an error.
$.getJSON("ajax/person_output.aspx", { 'uID': 1 }, function(data) {
$.each(data.items, function(i, item) {
$("<span/>").html(item.first_name).appendTo("#content");
});
});
ajax / person_output.aspx creates the following json (this is just for one post ..)
{
"l_id": "49",
"u_id": "1",
"first_name": "john",
"last_name": "doe",
"title" : "General Manager",
"color" : "333"
}
firebug generates the following error:
G is undefined
init()()jquery-1....2.min.js (line 12)
(?)()()URLINX5 (line 99)
I()jquery-1....2.min.js (line 19)
F()()jquery-1....2.min.js (line 19)
[Break on this error] (function(){var l=this,g,y=l.jQuery,p=l.....each(function(){o.dequeue(this,E)})}});
+1
a source to share
2 answers
I'm new to firebug but you need to figure out what's undefined here
$.getJSON("ajax/person_output.aspx", { 'uID': 1 }, function(data) {
$.each(data.items, function(i, item) {
$("").html(item.first_name).appendTo("#content");
});
});
This is either data, data.items, item, or item.first_name. If you are returning an array, you don't need to do something like data.items [i] and not item.first_name? The way you are setting it now, "element" is probably 0,1,2,3 ... n
0
a source to share