SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Refresh Div javascript/jquery/ajax script?

    Hi ,

    How to refresh particular DIV every few second....

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by robertaxel View Post
    Hi ,

    How to refresh particular DIV every few second....
    Put it in an iframe and give the head of the iframe a refresh directive.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Paul,
    Digging for an answer to a similar problem I have now, I found your answer.
    Can you please give an example on how to do what you mentioned(iframe)?
    Thanks in advance.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by esn003 View Post
    Hi Paul,
    Digging for an answer to a similar problem I have now, I found your answer.
    Can you please give an example on how to do what you mentioned(iframe)?
    Thanks in advance.
    HTML Code:
    <iframe src="targetpage.html"></iframe>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Paul,
    Can I put a php instead of html?
    How do you make it refresh at a give time interval?

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by esn003 View Post
    How do you make it refresh at a give time interval?
    You would put a meta-tag in the page that the iframe is loading, to perform the refresh. See http://reference.sitepoint.com/html/meta
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Paul, I will do just that.

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    41
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    @Paul: do we really advise people to use iframes? (I'm personally not fond of iframes at all...)

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Denk View Post
    @Paul: do we really advise people to use iframes? (I'm personally not fond of iframes at all...)
    iframes are not the only answer - it's preferable now to use setInterval to trigger an ajax request, and update the div in that manner.
    If using jQuery it would be something like:

    Code javascript:
    $('#target').data('timedupdate', window.setInterval(function () {
        $('#target').load('http://aaa.bbb.com/pagetoupdatefrom.html');
    }, 5000));

    The data part gives you the ability to use clearInterval on that timedupdate at some later stage, should you decide you want to do so.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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