I have the following MediaObject object that contains :
- a Media object
- an array
- and a function getMedia()
Within my getMedia function I make an ajax call and on success I want to be able to create a Media object and push that object into my array. However, I am unable to reference my array for some reason , how should I reference it ?
I've tried both : MediaObject.arrayList.push(mediaItem) and this.arrayList.push(mediaItem); Neither work.
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
thisisn't what you think it is. You should addcontext: thisto your ajax request to remedy that. (this will not solve your problem though)