I'm trying to create my first node.js program with socket.io and I want to store the chat history and then when a user joins have the chat history pushed to his browser. I have the chat saving and pushing and the json that is sent looks like this:
[
[
{
"username": "Warren2",
"text": "Test"
},
{
"username": "Warren2",
"text": "Test2"
},
{
"username": "Warren2",
"text": "Test3"
}
]
]
On my html page I have a javascript that has this
socket.on('updatehistory', function(data) {
}
The code that I put in there will be executed when the updatehistory message is pushed. I'm a n00b and pretty lost lol. This is what I tried:
socket.on('updatehistory', function (data) {
$.each(json.results, function(username,text){
$('#conversation').append('<b>'+ username + ':</b> ' + text + '<br>');
});
});
This is the exact debug message for the updatehistory event from node.js
debug - websocket writing 5:::{"name":"updatehistory","args":[[{"username":"W
arren2","text":"Test"},{"username":"Warren2","text":"Test2"},{"username":"Warren
2","text":"Test3"}]]}
Can someone help me figure out how to parse that (preferable with jquery). Thank you :D