Getting typeError:e is undefined in firebug while running a script

柔情痞子 提交于 2019-12-24 01:57:42

问题


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.

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.


回答1:


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

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 ;
       ......
   },



回答2:


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.



来源:https://stackoverflow.com/questions/16008119/getting-typeerrore-is-undefined-in-firebug-while-running-a-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!