3 Auto-Refreshing Divs on a page using JQuery but one of them doesn't work?
I have three divs on my page and each one is auto-refreshed using JQuery, here's the HTML:
<div id="photo">
<?php require("image.php"); ?>
</div>
<div id="right-bar">
<div id="facebook"> <?php require("graph.php"); ?></div>
</div>
<div id="bottom-bar">
<?php require("twitter.php"); ?>
</div>
Here is the JQuery:
var imagecacheData;
var imagedata = $('#photo').html();
var imageauto_refresh = setInterval(
function ()
{
$.ajax({
url: 'image.php',
type: 'POST',
data: imagedata,
cache: false,
dataType: 'html',
success: function(imagedata) {
if (imagedata !== imagecacheData){
//data has changed (or it's the first call), save new cache data and update div
imagecacheData = imagedata;
$('#photo').fadeOut("slow").html(imagedata).fadeIn("slow");
}
}
})
}, 60000); // check every minute
var cacheData;
var data = $('#facebook').html();
var auto_refresh = setInterval(
function ()
{
$.ajax({
url: 'graph.php',
type: 'POST',
data: data,
dataType: 'html',
success: function(data) {
if (data !== cacheData){
//data has changed 开发者_如何学Go(or it's the first call), save new cache data and update div
cacheData = data;
$('#facebook').fadeOut("slow").html(data).fadeIn("slow");
}
}
})
}, 30000); // check every 30 seconds
var twittercacheData;
var twitterdata = $('#bottom-bar').html();
var twitterauto_refresh = setInterval(
function ()
{
$.ajax({
url: 'twitter.php',
type: 'POST',
data: twitterdata,
dataType: 'html',
success: function(twitterdata) {
if (twitterdata !== twittercacheData){
//data has changed (or it's the first call), save new cache data and update div
twittercacheData = twitterdata;
$('#bottom-bar').fadeOut("slow").html(twitterdata).fadeIn("slow");
}
}
})
}, 60000); // check every minute - reasonable considering time it takes 5 tweets to scroll across
As you can see, all of them are pretty much the same thing but the twitter section doesn't auto-refresh at all.
Also, as you can see I am trying to only get the page to do the fade out/ fade in if the response is actually different but it seems to be doing it anyway - any ideas as to why this is?
Thank you for your help in advance
turns out it the problem was facebook wasn't signed in.
Soon as that was done it was fixed.
精彩评论