I am working on new app in javascript. What I need is that whenever latest news is added to the database at the backend then the front end should know about it and update that area asynchrnously. What is the best and efficient way to achieve this in JavaScript and/or jQuery?
Asked
Active
Viewed 79 times
3 Answers
2
I would recommend using long polling. With a quick Google search you should be able to get up and running. For example here.

Shane Haw
- 723
- 9
- 22
-
I don't think long polling is needed there if one request per 30 seconds should be enough, and immediate respond to new data is not forced. But long polling also can be an option as well. – Jan.J Aug 14 '13 at 06:05
0
use Window.setInterval() to reload the page for specific interval of time so that the news gets updated

Ramki
- 166
- 1
- 12
0
make a function get_news
which contains ajax
request which well get updated content from the server.
setInterval(get_news, 1000)
will call the function get_news
after every 1000 ms
function get_news() {
$.ajax({
type: "POST",
url: url,
data: data,
success: function (data) {
$('#content').html(data);
}
dataType: dataType
});
}
setInterval(get_news, 1000); //1000 ms

Tushar Gupta - curioustushar
- 58,085
- 24
- 103
- 107