views:

6544

answers:

2

When trying to use the code presented here link text I ran into some problems, which was suggested to open up a new question for this problem. Im an using that code here link text trying to create a backchannel for a meeting (it uses the twitter search api to display data, so try please try it with some hashkey to get data in). The problem is though, when the content gets it, it immediately disappears again as if the div get hidden. When looking at the source I can see the contents of the div there but it is not being displayed. Unless the timeout occurs and the error message for the timeout is being displayed then the contents of the div below will stay. For completeness I will put the code being used here:

             <script type="text/javascript">
    function update() {

 $("#notice_div").html('<img src="img/ajax-loading.gif" border="0"/>');
 $.ajax({
     type: 'GET',
 url: 'inc/backchannel.php',
        timeout: 2000,
 success: function(data) {
     $("#backchannelContent").html(data);
     $("#notice_div").html(''); 
     window.setTimeout(update, 2000);
 }, 
 error: function (XMLHttpRequest, textStatus, errorThrown) {
     $("#notice_div").html('Timeout contacting server..');
     window.setTimeout(update, 60000);
 }
    })}$(document).ready(update);
    </script>

Thanks in advance for any help, I'm not that much of a javascript coder so it feels like walking against a brick wall here :-(

+1  A: 

try something like this

function getRandom() {
    $("#random").hide("slow");
    $("#random").load("http://www.google.co.uk", '', callback);
}

function callback() {
    $("#random").show("slow");
    setTimeout("getRandom();", 10000);
}

$(document).ready(getRandom);
01
tried your suggestion avaible at test2.php instead of test.php and it gives the same problem...content gets loaded and the divs gets hidden :-(
+2  A: 

You're having problems because the div's content is loaded before the hiding animation is complete. You can solve it using another callback, like this:
(This is very similar to what Mark wrote, but with anonymous functions)

$(document).ready(function(){
  setInterval(function(){
    $("#random:not(:animated)").hide("slow", function(){
        $("#random").load("inc/backchannel.php").show("slow");
    });//show callback
  } ,10000);//set interval
});//doc.ready
Kobi
this one is very helpfull and definitely in the good direction the first time round it shows everything now and it stays shown...but when the refresh of the content hits in it is back to the 'be shown again and gone again'...maybe need to give a higher time for that set interval?
Could you upload a version to your server? this worked well for me.
Kobi
this code is uploaded to the server it can be found at http://togethr.org/test/test.php but like I said the first time it shows the page after a reload it goes wrong now :-( (you can try it with filling in something like 'superbowl' in the inputfield and hit enter)
try adding the ":not(:animated)" to the selector (see edited code), this will ensure the content is not reloaded while animating, which should synchronize it.
Kobi
did that just now (as you can see on the page) and it takes a wee bit longer now to go hidden, but it still goes hidden....wish I could have javascript skilzz myself, sorry any further suggestions?
Just making sure - when I go to http://togethr.org/test/inc/backchannel.php I get a *blank page*. If this page is loaded, this could explain why the div is blank. I tried adding a border to your div (via firefox), and it is visible but empty.
Kobi
ooooh that might be it ^_^ the submitform does a post and that variable should be included in the loading of the page off course so instead of loading inc/backchannel.php it should load inc/backchannel.php?some=variable that way it seems to work...thank you very much!