Ich habe eine Ajax-Werte von db bekommen, und das Ergebnis wird in ein Array geschoben:Extrahierung Array - undefined
function pushPONFail(dt, ct) {
if (ct < 12) {
var tMon = parseInt(dt.getMonth())+1;
var tYear = dt.getFullYear();
ct++;
} else {
return;
}
data = {"qType": 101,
"tbl": 'qualitypqa.dbo.centerthickness',
"month": tMon,
"year": tYear,
"type": 'Lotrafilcon B'};
$.ajax({
cache : false,
url: "getrpt.php",
type: "get",
data: data,
contentType: 'application/json; charset=utf-8',
async: true,
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("error: "+textStatus+" : "+errorThrown);
}
})
.done(function(response){
var obj = jQuery.parseJSON(JSON.stringify(response));
arrPONFail.push({Month: months[tMon-1]+"/"+tYear, PONFail: obj[0].PONFail});
dt = new Date(dt.setMonth(parseInt(dt.getMonth()) - 1));
pushPONFail(dt, ct);
});
} // pushing values such as ["May/2017", 0]
$(function() {
var dt = new Date();
pushPONFail(dt, 0);
console.log(arrPONFail);
});
Dies sind die komplette Funktion. Wenn ich das Array console.log anmelde, kam es als mein Bild heraus. Ich kann die Daten nicht extrahieren.
Wenn ich das Array in die Konsole drucke, kam es wie das Bild unten.
Wie bekomme ich die Werte aus dem Array zurück? Wenn ich ein arrT [0] mache, bekomme ich ein undefined.
Bitte beraten.
Sie sind Konsolenprotokollierung arrT außerhalb der .done(). Sie sollten die logarithmus-arrT-Konsole nach dem Abschluss von done() trösten, oder Sie können die Timeout-Funktion für 1000 Millisekunden aufrufen und dann arrT protokollieren. Sie werden den Unterschied sehen. – supritshah1289