Getting NaN from a JavaScript function trying to get the same data more than once

updateAction: function(postData) {
    console.log("updating from custom function...");
    return $.Deferred(function($dfd) {
        $.ajax({
            url: 'HallManagementServlet?action=UpdateStudent',
            type: 'POST',
            dataType: 'json',
            data: postData,
            success: function(data) {
                $.each(data, function(entryindex, entry) {
                    payment_date.push(entry['payment_expires_on']);  
                });
                var current_date = new Date();
                var current_date_in_millis = current_date.getMilliseconds();

                var last_payment_date = payment_date;
                alert(Date.parse(last_payment_date)+"Second 1"+Date.parse(current_date));
                $dfd.resolve(data);
            },
            error: function() {
                $dfd.reject();
            }
        });
    });
}

I am trying to make out two dates here. But last_payment_dategives me NaNif I try to get this value twice.

Why does this give me NaNwhen I try to change a list JTablemore than once?

+4
source share
2 answers

It seems that the culprit payment_dateandDate.parse()

Date.parse() can process an array of length 1

Date.parse(['01-01-2015']) // 1420088400000

Why does he give me NaN when I try to change my JTable list more than once?

, payment_date, , , , , 2 .

Date.parse(['01-01-2015', '03-03-2015']) // NaN

:

var data = ['10-03-2015', '01-01-2015', '03-03-2015'];
$.each(data, function(entryindex, entry) {
    payment_date.push(Date.parse(entry['payment_expires_on']));  
});

// ...

// Presumably the last payment date is chronologically the last one,
// but I am not sure if that is true or not.
payment_date.sort();

var last_payment_date = payment_date[payment_date.length - 1];
// last_payment_date is a now a timestamp, don't use Date.parse() on it.

// ...
+2

last_payment_date Array. :

Date.parse(last_payment_date[0])
+2

All Articles