Hi I have ajax which calls json, i wanted to have this json object a javascript global reference so that I can use this reference to access json object. here is code.
var jsonData;
$.getJSON(url, function(json) {
jsonData = json; /*i wanted to pass this json object to global reference*/
});
nextAlbum function(){
console.log(jsonData.albums.length); /*I have to acces here*/
}
your help will be appreciated. here is my latest code.
var mysplitSlider = (function(){
var init, findTotalAlbums, countAlbum;
var jsonData;
return{
init: function(url){
$.getJSON(url, function(json) {
jsonData = json;
});
},
nextAlbum:function(){
console.log(jsonData.albums.length);
},
previousAlbum:function(){}
};
})();
var url = "assets/images/detail_view_gallery/data.json";
mysplitSlider.init(url);
please help me so that I can access reference variable/object for json.
nextAlbum function() {...is a syntax error.