I try to accomplish a really simple Task
- Read data from a service in a jquery loop
- return the data to another function to plot it into a graph
Here comes the problem were i'm really stuck
function readData() {
var vname = $(this).attr("name");
var vid=$(this).attr("id");
var arrResult = [];
$("#choices").find("input:checked").each(function () {
var senddata = {
databaseURL: DB,
tracename: variablePath + vname+"\\"+vid,
startdate: jDateStart1,
enddate: jDateEnd1
};
var jsonUrl = "http://service/trace";
var jqxhr = $.get(jsonUrl, senddata, function(dataAI) {
arrResult.push(dataAI.value);
console.log(arrResult); <<< returns data
})
})
console.log(arrResult); // <<< returns nothing
return arrResult;
}
The Problem is that arrResult return empty, nothing, null and i really don't know why?? Shouldn't it be that for the anonymous function in the get statement the arrResult acts like a global variable?