473,704 Members | 6,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

timer does not work in IE

5 New Member
I have a Ajax / PHP timer code that would run and update timer on a webpage for 2 hrs. But in IE the time does not refresh and maintain its initial value.

Expand|Select|Wrap|Line Numbers
  1. function timer() { 
  2. //debugger; 
  3.    var xmlHttp; 
  4.    try { 
  6.       xmlHttp=new XMLHttpRequest(); 
  7.    } 
  8.    catch (e) { 
  9.       // Internet Explorer 
  10.       try { 
  11.          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
  12.        } 
  13.       catch (e) { 
  14.          try { 
  15.             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
  16.          } 
  17.          catch (e) { 
  18.             alert("Your browser does not support AJAX!"); 
  19.             return false; 
  20.          } 
  21.        } 
  22.    } 
  24.    xmlHttp.onreadystatechange=function() { 
  25.       if(xmlHttp.readyState==4) { 
  26.          document.onlinetestform.timer1.value = xmlHttp.responseText; 
  28.        } 
  29.    } 
  30.    xmlHttp.open("GET","time.php?time=06:51:00",true); 
  31.    xmlHttp.send(null); 
  32.    newtime = window.setTimeout("timer();", 1000); 
  33. }

function timeDiff($start Time) {

$tNow = date("h:i:s");
//echo $tNow."<br/>";

// Extract $current_date h:m:ss
$current_hour = substr($tNow,0, 2);
$current_min = substr($tNow,3, 2);
$current_second s = substr($tNow, 6, 2);

$start_hour = substr($startTi me,0,2);
$start_min = substr($startTi me,3,2);
$start_seconds = substr($startTi me, 6, 2);

$tFinishtime = mktime($start_h our+2, $start_min, $start_seconds) ;
$tCurrenttime = mktime($current _hour, $current_min, $current_second s);

$hoursround = floor(($tFinish time-$tCurrenttime)/3600);
$minutesround = floor((($tFinis htime-$tCurrenttime)/60) - (60 * $hoursround) );
$secondsround = ($tFinishtime-$tCurrenttime) - (60 * 60 * $hoursround) - (60 * $minutesround);

$hoursround = "0".$hoursround ;

if($secondsroun d < 10)
$secondsround = "0".$secondsrou nd;
if($minutesroun d < 10)
$minutesround = "0".$minutesrou nd;

echo $hoursround. ":". $minutesround. ":".$secondsrou nd;

Oct 7 '08 #1
4 1942
16,027 Recognized Expert Moderator MVP
Most likely this problem is caused by caching. To prevent it, either disable caching by setting the appropriate headers in the PHP page, or just add a unique timestamp to the end of the URL, e.g.
Expand|Select|Wrap|Line Numbers
  1. xmlHttp.open("GET","time.php?time=06:51:00&d="+(new Date()).getTime(),true);
Oct 7 '08 #2
5 New Member
Most likely this problem is caused by caching. To prevent it, either disable caching by setting the appropriate headers in the PHP page, or just add a unique timestamp to the end of the URL, e.g.
Expand|Select|Wrap|Line Numbers
  1. xmlHttp.open("GET","time.php?time=06:51:00&d="+(new Date()).getTime(),true);
Yup u were right thanks
Oct 7 '08 #3
16,027 Recognized Expert Moderator MVP
Excellent. Glad it's working :)
Oct 7 '08 #4
79 New Member
The root cause for this is because of the fact that IE caches the page .. since we use the XMLHTTP object.... so a time stamp fixes this...
Oct 9 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: redneon | last post by:
I have a program which is constantly reading from a stream and what I'm wanting to do is, if the stream hasn't sent anything after a certain amount of time then do something. I've tried doing this like this... while(!done) { idleTimer.Start(); response = streamReader.ReadLine(); idleTimer.Stop(); ....
by: Jim Hammond | last post by:
The following code tries to excute a function 10 seconds after Page_Load by using a Timer, but the callback never gets called. private void Page_Load(object sender, System.EventArgs e) { // Set timer to call Page_PostLoad in 10 seconds
by: vickey | last post by:
Hi, Im trying to make a page which refreshes by itself.For that i have added a timer with following properties: Autoreset = true Enabled = true interval = 30000 Name = timer1 on timer1_elapsed i have added the following code: Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As _ System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have never used this timer. I used the documentation from Microsoft as a guide, but I cannot get this timer to work. Protected Overrides Sub OnStart(ByVal args() As String) Dim myTimer As New TimerState()
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn library as I thought this would be a good start!!!) but nothing happens :- Imports System.Timers
by: Rainer Queck | last post by:
Hello NG, in my application I have a Panel, docked right to my Form. On this panel I draw - cyclic triggered by a System.Winforms.Timer - a bitmap using the Graphics class. using (Graphics g = pnlDisplay.CreateGraphics()) { g.DrawImage(myBitmap, 0, 0); }
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.