thanks in advance for any help and for reading this.
So, I am trying to utilize server data from a $.post response to manipulate graphs. However, this is causing me two problems.
1 - I have tried several times to pass a variable array created from within a $.post {}, which utilizes data returned from the server, into a global scope. However, I must be missing something and tried endless google and search but nothing is working. Can someone hint at the problem? Aka: I would like to have list_1 and list_2 accessible as a global variable outside of the $.post so that I can use it to insert into a tooltip. If I have the array with the necessary information then I can populate the tooltip with such data. Here is a cut down version of the code.
function OnSelectDay(selected) {
var list_1 = [];
var list_2 = [];
var Day = selected.split("/");
// Format is DD/MM/YYYY
// Day = Day[0]
var TheDay = parseInt(Day[0]);
var TheNextDay = parseInt(Day[0]) + 1;
$.post("_viewdata.php", { selected: selected }, function (data) {
for (var i in data.id) {
var time = data.hora[i];
time = time.split(":");
time = parseInt(time);
var temp = data.dia[i].split("-");
if (temp[2] == TheDay && time > 20) {
var num = data.codigo[i].split(".")
var num2 = parseInt(num[1]);
if (num2 === 1) { list_1.push(data.hora[i]) };
if (num2 === 2) { list_2.push(data.hora[i]) };
}
};
}, "json");
alert(list_1);
}
Problem Number 2:
I am actually creating about 20 arrays and to each I am pushing the value when a logical argument is made. Here is how I am doing it: (also seen above):
if (num2 === 1){list_1.push(data.hora[i])}; if (num2 === 2){list_2.push(data.hora[i])};
When I tried to create this dynamically by using:
if(num2 = num[1]) { var TheList = "list_"+num[1]; TheList.push(data.hora[i]) }
I get an error stating that TheList doesn't have a function. Any ideas why I can't push into this dynamically generated name for the appropriate list? If I replace the "TheList" with "list_1" then it works fine. I still have the problem, though of being within the $.post. It will alert the data only within it and blank outside the $.post{}.
Thanks all,