2

Im experimenting with some JQuery and timing. I use the code below just for test purpose. My problem is that my controller is only being called the first time. Subsequent calls to the method is not made. I tride making an "alert" in my javascript, it triggere each 10 secs, but my controller was never called, thus the text in ".page" never changes. Any ideas on why this is?

<!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 runat="server">
    <title>
        <asp:ContentPlaceHolder ID="TitleContent" runat="server" />
    </title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
    $(document).ready(function () {
        window.setInterval(Update, 10000);

    });

    function Update() {
        var url = "/Home/GetTime";
        $.get(url, function (data) {
            $(".page").html(data);
        });
    }
    </script>
    <div class="page">

    </div>
</body>
</html>

The method in my controller it should call:

public string GetTime()
        {
            return "<h1>"+DateTime.Now.ToString()+"</h1>";
        }
tereško
  • 58,060
  • 25
  • 98
  • 150
Brian Hvarregaard
  • 4,081
  • 6
  • 41
  • 77

1 Answers1

9

My guess is caching if you are using Internet Explorer. You could try using the $.ajax method setting cache: false and also make sure you try it out in other browsers.

There is also quite a bit of discussion here about what sounds like the same behaviour

Community
  • 1
  • 1
Paul Carroll
  • 1,523
  • 13
  • 15