0

I am attempting to re-create the solution seen here for keeping a session alive by using an HTTPHandler and making an AJAX call to it.

The solution does not appear to have worked, and when I tried to debug it by adding an alert(); just before the $.get(); the alert(); never got fired off. I copied and pasted the code from the example, so I'm not missing a semicolon or something. I even set an alert(); before the setTimeout(); and that one worked!

function setHeartbeat() {
    alert("I get here!");
    setTimeout("heartbeat()", 300000); // every 5 min
}

function heartbeat() {
    alert("I never seem to fire off!");
    $.get(
        "/SessionHeartbeat.ashx",
        null,
        function(data) {
            setHeartbeat();
        },
        "json"
    );
}

Any thoughts?

ShowJX1990
  • 77
  • 2
  • 11

1 Answers1

0

Both slon and Hans Kesting were right one the money.

The working javascript is:

    $(document).ready(function () {

        //alert("Document is ready.");

        // set the initial call
        setHeartbeat();

        function setHeartbeat() {
            //alert("setHeartbeat");
            setInterval(function () {
                heartbeat();
            }, 10000); // every 10 sec
        }

        function heartbeat() {
            //alert("heartbeat");
            $.get(
                "/SessionHeartbeat.ashx",
                null,
                function(data) {
                    setHeartbeat();
                },
                "json"
            );
        }

    });

Thank you both!

ShowJX1990
  • 77
  • 2
  • 11