Reverse ordered list for jquery submitted comments
Posted
by g-man
on Stack Overflow
See other posts from Stack Overflow
or by g-man
Published on 2010-03-24T20:00:20Z
Indexed on
2010/03/24
20:03 UTC
Read the original article
Hit count: 364
jQuery
Hey guys I have one more question lol. I am using a script that allows users to submit comments through jquery ajax, however when they are submitted, the submitted comments submit at the bottom of the other comments which are sorted in descending order (newest on top) when the page first loads (due to mysql query). Is there a way to make it submit on top through some sort of sorting javascript function?
function prepare(response) {
var d = new Date();
count++;
d.setTime(response.time*1000);
var mytime = d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();
var string = '<li class="shoutbox-list" id="list-'+count+'">'
+ '<span class="date">'+mytime+'</span>'
+ '<span class="shoutbox-list-nick"><a href="statistics.php?user='+response.user+'">'+response.user+'</a>:</span>'
+ '<span class="msg">'+response.message+'</span>'
+'</li>';
return string;
}
function success(response, status) {
if(status == 'success') {
lastTime = response.time;
$('#daddy-shoutbox-list').append(prepare(response));
$('input[name=message]').attr('value', '').focus();
$('#list-'+count).fadeIn('slow');
timeoutID = setTimeout(refresh, 3000);
}
}
<div id="daddy-shoutbox">
<ol id="daddy-shoutbox-list"></ol>
</div>
© Stack Overflow or respective owner