I'm writing some javascript code which first retrieves some data form the database (function $.get()) and then performs some calculations on the data - using CalcModule() with static properties to pass on the data to a function Test(). Via the console I see that the static properties (productname, productid) are set (within $.get()), but via the console I also see that these values are still not accessible (visible) for function Test()??
What am I doing wrong? (I checked a few sites about static properties suchs as http://elegantcode.com/2011/01/19/basic-javascript-part-7-static-properties-and-methods/, but I can still not fin the problem)
the code:
$(document).ready(function () {
function CalcModule() {};
//static variables
CalcModule.nrofeproducts;
CalcModule.productid = [];
CalcModule.productname = [];
//get the product data from the database
$.get("getdata.php",
function (msg) {
//some code here...
//load CalcModule with retrieved db values for calculation
for (var i = 0; i < msg.nrofeproducts; i++) {
CalcModule.productid[i] = msg.productid[i];
CalcModule.productname[i] = msg.productname[i];
}
//for debugging purposes
console.log(CalcModule.productname);
console.log(CalcModule.productid);
}, "json"); //$.get()
function Test() {
var x = [];
x = CalcModule.productname;
console.log(CalcModule.productname);
}
Test();
})