views:

370

answers:

2

If this question has already been asked I appologies, please point me in the right direction.

I was wondering if anyone has any insight into how StackOverflow pops up the "n new answers have been posted, load new answers" thing at the top of a question when you are adding a post. This seems like a very useful function for my forum web-site and I would like to know how it is done. I assume some ajax or advanced javascript of some kind.

+10  A: 

Look at this SO blog post: http://blog.stackoverflow.com/2008/10/solving-the-fastest-gun-in-the-west-problem/

That said, the one implementable recommendation that came out of this discussion is an active, GMail like notification when you are composing an answer. We agreed with this feature request, so Jarrod implemented it. Here’s how it works:

  1. When you start composing a reply, a timer is created.
  2. Every minute, the page checks itself to see if new answers have arrived.
  3. If new answers arrive, the notification bar will tell you how many, and offer to update the page for you.
  4. Answer updates are performed AJAX style, so they don’t interrupt your current answer.
amdfan
+2  A: 

At a guess it's using a jQuery timer object to query a JSON webservice every n seconds. Check out http://docs.jquery.com and http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/24/json_in_aspnetajax_part2.aspx.

How ironic... an answer has been posted as I was writing this.

Rob Stevenson-Leggett