I have an object that contains messages that are of JSON type. I have a method called .retrieve() that uses an AJAX request to download messages from the server. It will fetch the messages from the server then call a callback function with an array of strings (messages).
.retrieve():
Msg.retrieve = function(callBack) {
$.ajax({
url : '<url>',
type : 'GET',
dataType: 'JSON',
contentType : 'application/json',
data : JSON.stringify({
key : 'value: '
}),
error : function(data) {
console.log('error');
},
success : function(data) {
callBack(data);
}
});
}
I have a .display() method that will output the messages as list items in an unordered list like a chat client would.
.display()
Msg.display = function(text) {
if (typeof text == "undefined"){
$('.chat').append('<li>' + "" + '</li>');
} else {
$('.chat').append('<li>' + text + '</li>');
}
}
When I combine .display() and .retrieve() it gives me [object Object] as a list item in my browser.
Question: How do I output the messages rather than displaying [object Object] on my browser?