Link to home
Start Free TrialLog in
Avatar of n2alexan

asked on

AJAX response returns the same value only requesting current date time


I have a very simple webapp that has this index.htm page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
    <title>Untitled Page</title>

    <script type="text/javascript">
            function GetXmlHttp() {      
      var xmlhttp = false;
      if (window.XMLHttpRequest)
            xmlhttp = new XMLHttpRequest();
      else if (window.ActiveXObject)// code for IE
                  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            catch (e)
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                  } catch (E) {
      return xmlhttp;

            function ajaxFunction(url)
    var xmlHttp = GetXmlHttp();
        document.getElementById("ajaxin").value = document.getElementById("ajaxin").value + '|' + xmlHttp.responseText;

    <input id="Button1" onclick="ajaxFunction('ajax/tracker.aspx');" type="button" value="button" />
    <input id="ajaxin" style="width: 100%; height: 544px" type="text" />

and I use aspx page to write back the date and time

<% Response.Write(DateTime.Now) %>

but every time I press the button I get the same datetime and it's value is not changed, even after 1 minute.
The values of seconds is not updated.

Could someone explain what is happenning here.

Thank you very much,

Avatar of mark-b
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of n2alexan


Hi Mark,

Thank you for your response. Your solution does work!

I have found the explanation to the problem by searching for 'ajax caching' terms in Google. I came across David's blog who has stated Microsoft Internet Explorer Cache issues which he found  on this page.

Microsoft Internet Explorer cache issues
Internet Explorer implements caching for GET requests. Authors who are not familiar with HTTP caching expect GET requests not to be cached, or for the cache to be avoided as with the refresh button. In some situations, failing to circumvent caching is a bug. One solution to this is to use the POST request method, which is never cached; however, it is intended for non-idempotent operations.

Setting the "Expires" header to reference a date in the past will avoid caching of the response.
" (XMLHttpRequest - Wikipedia, the free encyclopedia, Wikipedia 2007).

Glad to help.  And good luck!