jquery - auto refresh div containing javascript - Stack Overflow

I want to refresh a DIV that has a JavaScript inside it every 5 seconds. I tried this code, but it only

I want to refresh a DIV that has a JavaScript inside it every 5 seconds. I tried this code, but it only refreshes one time. how can I make it execute the JavaScript code every five seconds ?

<html>
<head>
<script type="text/javascript" src="/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#content').load('count.html');
}, 5000); // refresh every 5000 milliseconds

</script>
</head>

<body>

<div id="content">
    <script type="text/javascript">

    today = new Date();
    BigDay = new Date("December 25, 2020");
    msPerDay = 24 * 60 * 60 * 1000 ;
    timeLeft = (BigDay.getTime() - today.getTime());
    e_daysLeft = timeLeft / msPerDay;
    daysLeft = Math.floor(e_daysLeft);
    e_hrsLeft = (e_daysLeft - daysLeft)*24;
    hrsLeft = Math.floor(e_hrsLeft);
    minsLeft = Math.floor((e_hrsLeft - hrsLeft)*60);
    document.write("There are only<BR> <H4>" + daysLeft + " days " + hrsLeft +" hours and " + minsLeft + " minutes left </H4> Until December 25th 2020<P>");
    </script>
</div>

</body>
</html>

I want to refresh a DIV that has a JavaScript inside it every 5 seconds. I tried this code, but it only refreshes one time. how can I make it execute the JavaScript code every five seconds ?

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis./ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#content').load('count.html');
}, 5000); // refresh every 5000 milliseconds

</script>
</head>

<body>

<div id="content">
    <script type="text/javascript">

    today = new Date();
    BigDay = new Date("December 25, 2020");
    msPerDay = 24 * 60 * 60 * 1000 ;
    timeLeft = (BigDay.getTime() - today.getTime());
    e_daysLeft = timeLeft / msPerDay;
    daysLeft = Math.floor(e_daysLeft);
    e_hrsLeft = (e_daysLeft - daysLeft)*24;
    hrsLeft = Math.floor(e_hrsLeft);
    minsLeft = Math.floor((e_hrsLeft - hrsLeft)*60);
    document.write("There are only<BR> <H4>" + daysLeft + " days " + hrsLeft +" hours and " + minsLeft + " minutes left </H4> Until December 25th 2020<P>");
    </script>
</div>

</body>
</html>
Share Improve this question edited Oct 31, 2013 at 10:39 TN888 7,7299 gold badges52 silver badges85 bronze badges asked Oct 31, 2013 at 9:57 MashaelMashael 1832 gold badges4 silver badges9 bronze badges 2
  • When I replace your $("#content").load() by alert() it works fine.. codepen.io/anon/pen/hldLe – EricG Commented Oct 31, 2013 at 10:01
  • refer this stackoverflow./questions/18503478/… – Sridhar R Commented Oct 31, 2013 at 11:35
Add a ment  | 

2 Answers 2

Reset to default 2

I found this answer to another question here: Auto Refresh DIV contents every 5 seconds code not working


I think your refresh function is inplete, for instance there's nothing that makes it loop. Try something like this:

$(document).ready(function () {
var seconds = 5000; // time in milliseconds
var reload = function() {
   $.ajax({
      url: 'editStatus.jsp',
      cache: false,
      success: function(data) {
          $('#refreshDIV').html(data);
          setTimeout(function() {
             reload();
          }, seconds);
      }
   });
 };
 reload();
});

Try this

$(document).ready(function(){
setInterval(function(){
     $('#content').load('count.html');
     }, 5000);
}); 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745291795a4620902.html

相关推荐

  • jquery - auto refresh div containing javascript - Stack Overflow

    I want to refresh a DIV that has a JavaScript inside it every 5 seconds. I tried this code, but it only

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信