CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2005
    Posts
    6

    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

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Aug 2005
    Posts
    6

    Re: Update DIV without updating the whole page

    Ah I'm sorry it should be www.digg.com/spy/

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    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;
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Update DIV without updating the whole page

    Actually, the revelant "magic" revolves around (and similar constructs):
    Code:
        timer2 = setTimeout('update()', updateDelay);
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Update DIV without updating the whole page

    Well, you wouldn't want setTimeout(), you would use setInterval() for a reoccurring event.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    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.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Update DIV without updating the whole page

    Which is why the "correct" solution could very much be application specific
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured