我无法弄清楚我的代码出了什么问题。我从帖子中获取数据作为数组,然后在框中显示该数据。
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(尽管 如果未指定,jQuery 将尝试根据该对象的 MIME 类型来推断它) 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 ;
......
},
关于javascript - 获取类型错误:e is undefined in firebug while running a script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16008119/