Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not sure why this won't update in IE.

    Hi there, I have a quick question.

    This script is fairly simple. It works great in firefox, doesn't seem to work in IE. My document.getElementById('theTime').value gets set in firefox, but not in IE.

    The php script returns a simple time string with the current server time, like March 10, 2005 11:15am, for example.

    In firefox, the time updates every 5 seconds as I would expect.

    In IE the time never changes and remains at the first value retrieved from the server. I'm returning no-cache headers from the php script.

    Anyone have any ideas?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title>XmlHttpRequest</title>
    
    <script language="javascript" type="text/javascript">
      var url = "echotime.php?param=";
      var http = getHTTPObject();
      
      function startAjax()
      {
        getTime();
        setInterval('getTime();', 5000);
      }
      
      function handleHttpResponse()
      {
        if (http.readyState == 4)
        {
       if (http.status == 200)
       {
             document.getElementById('theTime').value = http.responseText;
       }
       else
       {
       alert("There was a problem retrieving the XML data:\n" + http.statusText);
       }  
        }
      }
      
      function getTime()
      {
        http.onreadystatechange = handleHttpResponse;
        http.open("GET", url, true);
        http.send(null);
      }
      
      function getHTTPObject()
      {
       if (window.XMLHttpRequest)
       {
          try
          {
            xmlhttp = new XMLHttpRequest();
          }
          catch (e)
          {
            xmlhttp = false;
          }
       }
       else if (window.ActiveXObject)
       {
          try
          {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
            window.alert("ms.xmlhttp");
            try
            {
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (E)
            {
              xmlhttp = false;
            }
          }
       }
       return xmlhttp;
      }
    </script>
    
    </head>
    <body onload="startAjax();">
    
    <form action="post" ID="theForm">
      <label for="time">time</label>
      <input type="text" name="test" id="theTime" width="200px" size="200px" value="crap"/>
    </form>
    </body>
    </html>

  • #2
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have added alerts and I know that it's doing a GET on the url, just not updating the .value in IE.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Does it go inside http.status 200 condition? Does it throw any error?

    Try adding time in the url to avoid caching.

    http.open("GET", url + new Date().getMilliseconds(), true);

  • #4
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, thanks for replying. Yes it does go into the status 200 block. I've verified with an alert in there.

    Also, earlier I tried adding a url + math.random() and that wasn't effective either.

  • #5
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    The solution

    In case anyone wonders, the solution dealt with the way MS's activex object works.


    As for IE - If you add the following as the first line of getTime():


    Code:
    http = getHTTPObject();


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •