javascript 运行脚本时在萤火虫中未定义 typeError:e
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16008119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting typeError:e is undefined in firebug while running a script
提问by RiderHood
I am not able to figure out what is wrong with my code.I am getting data from post as an array and I am then displaying that data in box.
我无法弄清楚我的代码有什么问题。我从 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);
}
});
}
When i run it firebug shows error: TypeError: e is undefined.
当我运行它时,firebug 显示错误:TypeError: e 未定义。
回答by bipen
since your sending the response as JSON.. its better to specify your dataType
as JSON (though If none is specified, jQuery will try to infer it based on the MIME type of the response
) so that you don't have to parse it manaully..i think the problem here is you havn't parsed the json that you got as response
因为您将响应作为 JSON 发送..最好将您的响应指定dataType
为 JSON(尽管 If none is specified, jQuery will try to infer it based on the MIME type of the response
),这样您就不必手动解析它..我认为这里的问题是您没有解析作为响应获得的 json
try this
试试这个
$.ajax({
url: '/index.php/admin/getLatest',
dataType: 'json',
success: function(data) {
$.each(data.upda,function(i, v){
var out = v.name + v.mob ;
......
},
回答by luisZavaleta
Check if data.upda is undefined, I think the problem is that that variable doesn't exist and you're trying to iterate over a undefined element.
检查 data.upda 是否未定义,我认为问题在于该变量不存在并且您正试图遍历未定义的元素。