admin管理员组

文章数量:1332377

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);
            });
        },
        plete: function() {
            // Schedule the next request when the current one's plete
            setTimeout(worker, 50000);
        }
    });
}

When i run it firebug shows error: TypeError: e is undefined.

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);
            });
        },
        plete: function() {
            // Schedule the next request when the current one's plete
            setTimeout(worker, 50000);
        }
    });
}

When i run it firebug shows error: TypeError: e is undefined.

Share Improve this question edited Apr 15, 2014 at 16:57 user2102869 asked Apr 15, 2013 at 5:19 RiderHoodRiderHood 791 gold badge1 silver badge7 bronze badges 12
  • Have you followed the stack trace of the error ? – AllTooSir Commented Apr 15, 2013 at 5:20
  • 2 The quoting in the initialisation of var a is broken. Is it that way in the original code? – michaelb958--GoFundMonica Commented Apr 15, 2013 at 5:21
  • No it was not broken in my original code. – RiderHood Commented Apr 15, 2013 at 5:24
  • i think there is some other code that is breaking your script... post other function where youare using the e – bipen Commented Apr 15, 2013 at 5:24
  • 2 @user2257655 It doesn't matter if you encode it as JSON...jQuery doesn't know what you're sending back. Just set the dataType option as "json". Like $.ajax({ url: '/index.php/admin/getLatest', dataType: "json", success: func... }); – Ian Commented Apr 15, 2013 at 5:35
 |  Show 7 more ments

2 Answers 2

Reset to default 4

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

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.

本文标签: javascriptGetting typeErrore is undefined in firebug while running a scriptStack Overflow