I'm creating a little web application and I would like to update the newest data on a field from SQL database on server WITHOUT refreshing the whole page. Is this possible and if yes, how can I do that?
I think I could use jQuery to refresh the whole page from time to time, but I don't think that's very wise, especially on heavier sites, because that would cause a lot of traffic. Instead I would like to update just couple fields with the newest data from the database.
var refresh = function() {
location.reload(true);
}
$(document).ready(function() {
setTimeout(refresh, 10000);
});
That's pretty much all I've got so far.
I found another similar question and there people suggested using XMLHttpRequest. Is it possible to use that to get some data from SQL database?
Also when trying to figure out that possible XMLHttpRequest solution, I found out that it could be possible to convert that XMLHtppRequest to SQL query by using some .ASP file, but as much as I understood the whole procedure that would require some Microsoft server framework and anyway it seemed to be quite rough and hard way to go when compared to the size and purpose of the whole application I'm programming. Especially when my whole site is running on Linux.
Moreover, I've read quite a lot about websockets and observer pattern. In theory the sound great and exactly what I need, but well, I'm quite new with these things and I wouldn't like to go that way yet, if I can avoid that. But if there's some easy way to do it and someone could show me a good tutorial about it, I'd be happy as well.
But at the moment I'm primarily looking for a way to do that "good old polling" no matter how ineffective it is. I think it still is a way better than to reload the whole page.
All kind of advice is highly appreciated.