获取typeError:运行脚本时,在firebug中未定义e

我无法弄清楚我的代码有什么问题。我从post中获取数据作为数组,然后我在框中显示该数据。

function worker() { var a = $("#BeeperBox"); var delay =2000; $.ajax({ url: '/index.php/admin/getLatest', success: function(data) { $.each(data.upda,function(i, v){ var out = v.name + v.mob ; $('span.blueName').html(out); $("#BeeperBox").show(); timerId = setTimeout(function () { a.hide(); }, delay); }); }, complete: function() { // Schedule the next request when the current one's complete setTimeout(worker, 50000); } }); } 

当我运行它时,firebug显示错误:TypeError:e未定义。

因为您将响应作为JSON发送..最好将您的dataType指定为JSON(尽管If none is specified, jQuery will try to infer it based on the MIME type of the response ),这样您就不必手动解析它..我认为这里的问题是你没有解析你得到的json作为回应

试试这个

  $.ajax({ url: '/index.php/admin/getLatest', dataType: 'json', success: function(data) { $.each(data.upda,function(i, v){ var out = v.name + v.mob ; ...... }, 

检查data.upda是否未定义,我认为问题是该变量不存在,并且您正在尝试迭代未定义的元素。