Update DIV without updating the whole page
I want to do a function like Digg Live. I have a file that prints out the latest 10 rows in my database. And everytime a new entery is added to the database, I would like the DIV to be printed out like it does on Digg Live.
I've read about HTTP requests but I still don't have a clue what to do.
Can someone help me with this, or point me in the right direction. Maybe you know a tutorial or a premade script that looks something like this.
Thanks in advance / Media12
Re: Update DIV without updating the whole page
The Digg live link that you have is invalid. Do you have a better link.
Concerning writing dynamically to a <div> just change the innerHTML content.
Re: Update DIV without updating the whole page
Ah I'm sorry it should be www.digg.com/spy/
Re: Update DIV without updating the whole page
It's just dynamically writing div content. It is the same as doing...
Code:
document.getElementById('div_id').innerHTML = content + document.getElementById('div_id').innerHTML;
Re: Update DIV without updating the whole page
Actually, the revelant "magic" revolves around (and similar constructs):
Code:
timer2 = setTimeout('update()', updateDelay);
Re: Update DIV without updating the whole page
Well, you wouldn't want setTimeout(), you would use setInterval() for a reoccurring event.
Re: Update DIV without updating the whole page
Hey I just looked at the source code of the referenced page....
While I agree that SetInterval is a better design (usually), SetTimeout can also be used (you just have to set the timeout inside of the invoked function to make it repeat).
Also SetTimeout will control the time between the end of call #n and the start of call #n+1. SetInterval will control the time between start #n and start #n+1. If there is a possibility of execution(x)>interval(x), then this design pattern can prevent stacking or recursive calls.
Re: Update DIV without updating the whole page
Quote:
Originally Posted by TheCPUWizard
While I agree that SetInterval is a better design (usually), SetTimeout can also be used (you just have to set the timeout inside of the invoked function to make it repeat).
Yes, but it is slower in its response time and more CPU intensive.
Quote:
Originally Posted by TheCPUWizard
Also SetTimeout will control the time between the end of call #n and the start of call #n+1. SetInterval will control the time between start #n and start #n+1. If there is a possibility of execution(x)>interval(x), then this design pattern can prevent stacking or recursive calls.
This is true, but also remember that setInterval() is not meant to execute heavy code on a high-rate interval.
Re: Update DIV without updating the whole page
Which is why the "correct" solution could very much be application specific :D