user3732216 user3732216 - 1 month ago 6
Ajax Question

CountUp Javascript Package and self.d is null

Any ideas on why I would be getting the following error with the countUp Javascript package.


TypeError: self.d is null


<script>
var numPendingOrders = $.ajax({
type: "GET",
url: "/admin/orders/getPendingOrders",
});

var options = {
useEasing : true,
useGrouping : true,
separator : ',',
decimal : '.',
prefix : '',
suffix : ''
};
var users = new CountUp("numPendingOrders", 0, numPendingOrders, 0, 5, options);
users.start();
</script>

Answer

You assign the

$.ajax({
        type: "GET",
        url: "/admin/orders/getPendingOrders",
    });

to your numPendingOrders which is not the result of the ajax call.Instead do like

$.ajax({
        type: "GET",
        url: "/admin/orders/getPendingOrders",
        success: function(data){
          var options = {
            useEasing : true,
            useGrouping : true,
            separator : ',',
            decimal : '.',
            prefix : '',
            suffix : ''
          };

           var users = new CountUp("numPendingOrders", 0, data, 0, 5, options);
           users.start();
        }
    });