How does StackOverflow know when there are new answers to a question?
Asked Answered
U

2

11

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.

Urine answered 30/10, 2008 at 15:0 Comment(2)
Edited to make this more clearly a real question.Elisavetpol
That is a much better question then mine, thanks :)Urine
P
12

Look at this SO blog post: https://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.
Paintbrush answered 30/10, 2008 at 15:1 Comment(0)
E
3

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 Link.

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

Experience answered 30/10, 2008 at 15:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.