I'm trying to store data from a xml-file in a associative Array. Creating the array works fine but I can't access the data in other functions (i.e. checkArray()).
var picSetsData = (function () {
var _picSets = [];
$.ajax({
type: "GET",
url: "xml/content.xml",
dataType: "xml",
success: function (xml) {
$(xml).find('set').each(function (i) {
_picSets[i] = [];
_picSets[i].fehler = [];
_picSets[i].url = $(this).find('src').text();
$(this).find('spot').each(function (e) {
_picSets[i].fehler[e] = [];
_picSets[i].fehler[e].x = $(this).find("x").text();
_picSets[i].fehler[e].y = $(this).find("y").text();
});
});
}
});
return {
getPicSets: function () {
if (_picSets) return _picSets;
else {
console.log('error');
}
}
};
})();
checkArray();
function checkArray() {
console.log(picSetsData.getPicSets().length); // 1
console.log(picSetsData.getPicSets()); // my Array Data
console.log(picSetsData.getPicSets()[1]); //undefinded
console.log(picSetsData.getPicSets()[1].url); //undefinded
}
Any ideas to solve this? Thx.