2009-05-18 58 views
1

我的页面中有以下代码。我期望从person_output.aspx页面返回一系列json对象,它可以成功执行。但是,当涉及到输出内容时,我收到一个错误。无法获得jQuery输出我的json对象

$.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产生以下JSON(这仅仅是为了一个记录..)

{ 
    "l_id": "49", 
    "u_id": "1", 
    "first_name": "john", 
    "last_name": "doe", 
    "title" : "General Manager", 
    "color" : "333" 
} 

萤火产生以下错误;

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)})}}); 
+0

该错误似乎与变量G.是否定义在任何地方? – aleemb 2009-05-18 19:39:08

+0

变量“G”是jquery被压缩的结果。你应该尝试使用jQuery的开发版本来运行它,并在这种情况下查看输出是否更有意义。 – fforw 2009-05-18 19:59:13

回答

2

您的JSON结果中的颜色属性后面有一个逗号,删除它有帮助吗?

0

我是新来的萤火虫,但你需要弄清楚这到底是怎么


$.getJSON("ajax/person_output.aspx", { 'uID': 1 }, function(data) { 
      $.each(data.items, function(i, item) { 
      $("").html(item.first_name).appendTo("#content"); 
       }); 
      }); 

不确定这是任何数据,data.items,项目或item.first_name。如果你要返回一个数组,你不需要做像data.items [i]这样的事情,而不是item.first_name?您现在设置的方式,“项目”可能是0,1,2,3 ... n