Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I'm wondering how SO is able to display the "New answers have been posted" message when I'm typing an answer for a question. Does my browser send an AJAX request to the SO servers, or does SO send a trigger back to my browser?

share|improve this question
up vote 6 down vote accepted

SO can't send trigger to the browser due to the very nature of web.

SO is using AJAX indeed, here is part of the code responsible for that nice message:

var count = parseInt(data.message);
if(count > 0) {
    var msg2 = count + " new answer" + (count == 1 ? " has" : "s have") + " been posted - ";
    msg2 += '<a onclick="heartbeat.answer.update()">load new answers.</a>';, notifyMessageTypeId);

The server is sending back the amount of new answers and if positive, the message is displayed.

If you really want, shouldn't be too hard to find the actual code invoking the AJAX request. :)

EDIT: This is not relevant anymore due to real time updates using web sockets:
New Feature: real time updates to questions, answers, and inbox

share|improve this answer
Does the the browser poll the server at regular intervals ? – Subhra Jul 5 '12 at 8:24
@Subhra not anymore, now it's using web sockets which is new feature and allows two way communication. Not sure what happens in case of browser not supporting it (currently only Chrome does) so I asked the developers and waiting for answer. – Shadow Wizard Jul 5 '12 at 8:38
Please let me know if you get the answer . I need to implement similar thing and the solution should be cross browser. – Subhra Jul 5 '12 at 8:51
@Subhra so use AJAX mechanism like it was used here, it will take long time until web sockets become cross browser. – Shadow Wizard Jul 5 '12 at 9:09

The former; it sends an AJAX request to /posts/POSTID/edit-activity-heartbeat every 45 seconds or so, and gets back info like if any new answers have been posted, or if the post has been deleted (so the answer button can be grayed out)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .