Results 1 to 7 of 7

Thread: Ajax Refresh DIV

  1. #1
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Ajax Refresh DIV

    Hi I am trying to get the div to auto refresh every 3second however it is not refreshing at all.

    Code:
    <div id="container">
                This is the default text
            </div>
            <script type="text/javascript">
               function rotateAds() {
    if (!document.phpAds_used) document.phpAds_used = ',';
    phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
    var r = (document.referer)? "&amp;referer="+escape(document.referer) : "";
    
    var b = document.getElementById("container");
    b.innerHTML = '<span style="font-size:20px;">Currently hosting <span id="stats-number"><?php echo JText::sprintf( $totalMembers );?></span> Members, <span id="stats-number"><?php $query = mysql_query("SELECT * FROM jos_community_groups WHERE published='1'"); $number=mysql_num_rows($query); echo "". $number; ?></span> Groups, <span id="stats-number"><?php $query = mysql_query("SELECT * FROM jos_seyret_items WHERE published='1'"); $number=mysql_num_rows($query); echo "". $number; ?></span> Videos, <span id="stats-number"><?php $query = mysql_query("SELECT * FROM jos_community_photos WHERE published='1'"); $number=mysql_num_rows($query); echo "". $number; ?></span> Photos and <span id="stats-number"><?php $query = mysql_query("SELECT * FROM jos_community_wall WHERE published='1'"); $number=mysql_num_rows($query); echo "". $number; ?></span> Wall posts.</span>';
    }
    function Refresh() {
        window.setInterval(rotateAds(),300);
    } 
            </script>
    The web in one word.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here:
    Code:
    function rotateAds() {
      if (!document.phpAds_used) document.phpAds_used = ',';
      phpAds_random = new String(Math.random());
      phpAds_random = phpAds_random.substring(2, 11);
      var r = (document.referer) ? "&amp;referer=" + escape(document.referer) : "";
    
      var b = document.getElementById("container");
      b.innerHTML = '<span style="font-size:20px;">Currently hosting <span id="stats-number"><?php echo JText::sprintf( $totalMembers );?></span> Members, <span id="stats-number"><?php $query = mysql_query("SELECT * FROM jos_community_groups WHERE published='
      1 '"); $number=mysql_num_rows($query); echo "". $number; ?></span> Groups, <span id="stats-number"><?php $query = mysql_query("SELECT * FROM jos_seyret_items WHERE published='
      1 '"); $number=mysql_num_rows($query); echo "". $number; ?></span> Videos, <span id="stats-number"><?php $query = mysql_query("SELECT * FROM jos_community_photos WHERE published='
      1 '"); $number=mysql_num_rows($query); echo "". $number; ?></span> Photos and <span id="stats-number"><?php $query = mysql_query("SELECT * FROM jos_community_wall WHERE published='
      1 '"); $number=mysql_num_rows($query); echo "". $number; ?></span> Wall posts.</span>';
    window.setTimeout(function(){ rotateAds(); }, 300);
    }
    But thats not ajax, its just putting php in javascript.
    Jeremy | jfein.net

  3. #3
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi, Thanks however I don't use phpAds and also for some reason it is not refreshing?

    All i need is for that div to refresh and the content inside it to do also.
    The web in one word.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    What do you mean you don't use PhpAds, the code I gave you is the same as your code except for the last 4 lines.
    Jeremy | jfein.net

  5. #5
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I found that code from google auto ajax refresh div
    I am just looking for away to refresh a div automatically after so many seconds.
    The web in one word.

  6. #6
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Last edited by Snookerman; 04-10-2009 at 09:01 AM. Reason: typo

  7. #7
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    one question,
    Code:
    	<script src="http://www.google.com/jsapi" type="text/javascript"></script>
        <script type="text/javascript">
            google.load("jquery", "1.3.2");
        </script>
        <script type="text/javascript">
        
            function getFresh() {
                
                     $("#stats").load("members.php", function() {
                        $("#stats").fadeIn();
                    });
                };
        
        	$(function(){
        		getFresh();
        		var int = setInterval("getFresh()", 100);
        	});
        	
        </script>
    how would i make it so that it refreshes whats in the div?
    The web in one word.

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
  •