Question about inserting a tablerow
I do an ajax call to the server and now I want to update a table by adding a new row (which, conveniently, is json data returned by the ajax call.)
Here is my success function from the call to $.post():
function(json) {
if (json) {
d = new Date();
d.setTime(json.date*1000);
dateString = d.format('d mmm, yyyy');
//this is kinda ugly, how can I make it better
newrow = '<tr><td>' + json.name + "</td><td>" + json.geo;
newrow += '</td><td>' + dateString + "</td><td class='hiscor'>" + json.time;
newrow += '</td></tr>';
$('#highscoresDrag table tbody :last-child').not('td, th').after(newrow);
} else {
alert('Score Not Successfully updated ');
}
},
This works, but, is there some cleaner way to create the row so I don't have so much markup embedded in my javascript. (so I could change the layout without rewriting my code.)
Thanks for all help. Hope to be answering questions here soon instead of asking so many. :)