views:

731

answers:

4

The best example of this is through SO. You can be viewing a question, and without refreshing the page you will get an orange message at the top of the screen letting you know you got a badge and check your profile. This all happens without refreshing the page.

I am curious how you go about doing that? I am going to guess something with AJAX. Any direction would be great.

+1  A: 

ASP.Net AJAX would be my suggestion for a starting point as there is a lot of different pieces all working together here, including ASP.Net MVC, Javascript, and built in AJAX support in ASP.Net.

JB King
Is there a non .NET example you know of? I am trying to do this for my company and they do not support .NET
Ascalonian
+2  A: 

It's just AJAX. Your server-side technology doesn't matter so much, so long as you have a web server that can respond to a client-side XMLHTTPRequest.

bigmattyh
But how does the message know you got a new badge? Does it keep sending a request to the server, which checks the database and returns which badge, if any?
Ascalonian
Yes, there would be a sleep that would check with the server every X seconds to see changes may have occurred.
Suroot
On SO, this is done every 60 seconds, I believe.
bigmattyh
Wouldn't that create a lot of load for a busy site? What would be the best practice?
Picflight
@Picflight: Busy sites generally benefit from AJAX calls like this, since the request and response are typically exchanging far less data than if user refreshes the page completely. That said, if you set the timeout to, say, 1 second, that would be a much heavier load on the server. The SO guys chose 60 seconds probably because it provides current-enough info without hitting the server too hard.
bigmattyh
+6  A: 

If you don't want to roll your own, look into Prototype (the JavaScript library) or jQuery, et al. They work well with several frameworks (such as Rails) or you can use them with your own custom setup.

MarkusQ
+2  A: 

jQuery dialogs, part of the jQuery UI are pretty nice. Other than that, just show hide certain elements on the page that you've positioned using CSS.

rball