PDA

View Full Version : Ajax Refresh DIV



queerfm
04-09-2009, 02:40 PM
Hi I am trying to get the div to auto refresh every 3second however it is not refreshing at all.



<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>

Nile
04-09-2009, 02:59 PM
Here:


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.

queerfm
04-09-2009, 04:29 PM
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.

Nile
04-10-2009, 05:44 AM
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.

queerfm
04-10-2009, 06:59 AM
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.

Snookerman
04-10-2009, 07:35 AM
This tutorial might be helpful: http://css-tricks.com/video-screencasts/60-ajax-refreshing-rss-content/ (http://css-tricks.com/video-screencasts/60-ajax-refreshing-rss-content/)

Good luck!

queerfm
04-10-2009, 08:19 AM
one question,


<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?