How to implement a twitter like message appearance?
I'm now developing comment system for my site on Ruby on Rails. I try to make comments to be appeared when user click on SEE MORE button. I see this is not like we do in pagination, so I need your little help guy开发者_C百科s!
When all comments have been displayed, the SEE MORE button should be removed from the page.
When the page loads, include a Javascript variable to indicate the "last item seen" or a time stamp (which I believe Twitter does as it orders the tweets in date order). You then have a Javascript function initiated by the setTimeout function which polls your server with this timestamp.
Your server then looks up to see if there has been any more posts since that point and if there has been, returns the number of results to the Javascript with an instruction to show a "See more" prompt - it also includes a new timestamp (if there are no new results, it just returns a timestamp).
Clicking on the "See more" prompt will then load in the new posts via Javascript, display them via the DOM and then reset the Javascript variable and repeat the process.
Of course, how you actually implement this will depend on how your data is structured, the server software you are actually using, what you actually want to do on the client side if there are new posts and then have often you want to "poll" the server for new responses (baring in mind more frequent polls will increase your server load).
Have you checked out this JQuery plugin. I believe it does pretty much exactly what you're looking for, and the example shows how to set it up using Rails. It's styled on the Facebook "Show more posts" pagination but this is basically the same as the "More" posts pagination as used by Twitter.
精彩评论