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>";
        }
1
  • Any errors on the page? In your debugging tools do you see the request get sent? Commented Dec 26, 2011 at 23:49

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.