Reputation: 955
I just want to have an idea on how to make a notification in my website without refreshing the web page. For example someone is post a comment in my wall like in facebook. I want it to notify me even if I'm not refreshing my page.
I'm thinking the idea like showing running time in a website. But I think I will retrieve some data from database every minute and it might cause a lot of traffic in network..
Please help me to have an idea on this. I would appreciate it if you can give me an idea or advice.
Thank you so much..
Upvotes: 0
Views: 1684
Reputation: 41
The way I do this is by using Javascript & AJAX on the page
something like this
<script>
function FetchNew(){
$.get("/Comments/Fetch",function(response){
for(var i = 0; i < response.messages.length; i++){
$("#messagecontainer").append('<div class="message">'
+ response.messages[i].content + '</div>');
}
});
</script>
What this basically does is
start an AJAX get request to the URL /Comments/Fetch ($.get)
when a response is received (i've assumed your backend script returns a JSON object array) go through each "message" or "comment" in the array (for (var i = etc etc))
append the contents of each message to the div with id messagecontainer
its HTML counter-part would look like this
<div id="messagecontainer">
YOUR MESSAGES APPENDED HERE
</div>
hope that helped
Upvotes: 4
Reputation: 11763
Another option is XSockets.
It can talk between JS and C#, and gives you real time notification for subscribed events.
They have some examples on the website, and even though ATM the documentation is a bit lacking, the developers are very responsive and I've got responses whenever I had an issue :)
Upvotes: 2
Reputation: 31479
I'm not aware of solutions for c# or asp-net, but there is http://socket.io/ which is widely used also on large-scale sites. It's implemented in JavaScript and runs on NodeJS.
Upvotes: 0
Reputation: 5830
You can use Knockout for this purpose.
However, I'm not familiar with the subject, but here's a great blogpost about Push Notifications.
Upvotes: 0