I have a MediaObject object that includes:
- a Media object
- an array
- and a function called getMedia()
When attempting to create a Media object and push it into the array inside the getMedia function after making an AJAX call, I encountered issues referencing the array. How should I properly reference it?
I have tried using both MediaObject.arrayList.push(mediaItem) and this.arrayList.push(mediaItem), but neither of them worked.
function MediaObject(){
function Media(){
this.id = "";
}
this.arrayList = [];
AmebaObject.prototype.getMedia = function(){
$.ajax({
url: this.rooturl+ this.loginurl,
type: 'GET',
headers: myheaders,
dataType: 'xml',
success: function (xml) {
this.xml = xml;
$(xml).find("media").each(function(){
var mediaItem = new Media();
mediaItem.id = $(this).find('id').text();
MediaObject.arrayList.push(mediaItem);
});
},
error: function (xhr, textStatus, errorThrown) {
console.log("Status code : " + xhr.status);
console.log("Error: " + errorThrown);
}
});
}
}
Error: Uncaught TypeError: Cannot call method 'push' of undefined