General Community > Scripting Help

Refresh DIV which contains external javascript

(1/3) > >>

Aaron10:
Hi, I'm trying to have a DIV that contains external javascript (it's an ad code - I've gotten permission) refresh every 30 seconds. However I've tried many codes and none seem to work, here's the current code I have:


--- Code: ---<script type='text/javascript'>
$(document).ready(function(){
     var update = function(){
          $('#ads')
               .load('http://www.ads.com/adcode.php')
               .fadeIn("slow");
     };

     var auto_refresh = setInterval(function(){update();}, 30000);
     update();
});
</script>
--- End code ---

Which is in the head, then I just add id="ads" to the div tag in the body, but it doesn't refresh. I've also tried these:

http://www.brightcherry.co.uk/scribbles/jquery-auto-refresh-div-every-x-seconds/

http://www.9lessons.info/2009/07/auto-load-refresh-every-10-seconds-with.html

Neither work, I'm guessing they were designed to use local php/js files? Or they don't work when javascript is within the DIV.

Anyway hopefully someone can help me with this, thanks.

Arantor:
All that code relies on jQuery, which is not part of SMF's default distribution. You need to add jQuery to your page before that code.

Aaron10:
This is for a regular HTML page

Arantor:
Doesn't matter. You still need to add jQuery to that page before that code. $(...) is a jQuery construct.

Aaron10:
This is the one off brightcherry:


--- Code: ---<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
 $(document).ready(function() {
  $("#responsecontainer").load("response.php");
   var refreshId = setInterval(function() {
      $("#responsecontainer").load('response.php?randval='+ Math.random());
   }, 9000);
   $.ajaxSetup({ cache: false });
});
</script>
--- End code ---

That's it right? It doesn't work though

Navigation

[0] Message Index

[#] Next page

Go to full version