I have a list of numbers (ex."20,145") that returns from an ajax call and I am pushing them to a js array. After reading the first index of list console.log(list[0]) I got undefinied on console screen. I need to use them inside DOMContentloaded function.
<script>
var list = [] //my empty list
for (var i = 1; i < 13; i++)
{
checkMonth(i); //calling function 12 times because of the months count
}
function checkMonth(n)
{
$.ajax
({
type: "POST",
url: "Homepage.aspx/BringDatas",
data: "{'month':'" + n + "'}",
contentType: "application/json; charset=utf-8",
dataType: "text",
success:
function (output) {
var sendedvalue = JSON.parse(output);
list.push(sendedvalue.d);//that returns numbers like "20,456"
},
error:
function () {
alert("hata var");
}
});
}
document.addEventListener("DOMContentLoaded", function ()
{
// after getting all values I inserted list I can see on console screen and it works
var person = [];
person = list;
console.log(list); // that works succesfull
console.log(list[0]) // that is not working