0

I have a static dictionary style counter that decrements when a user leaves a page. I can hit F5 or Crtl-F5 in a browser like Firefox and it Decrements fine.

However, if I spam crtl-F5 then the decrement operation does not take place. Maybe the page is refreshing faster than the javascript can load.

Is there any way around this? The code below runs when a user leaves the page.

I should mention that I am incrementing in the page_load event (asp.net)

 // decrement
window.onbeforeunload = confirmExit;
function confirmExit() {
    var request = {
        "channelId": channelId
    };

    // needed for ie7
    var params = $.toJSON(request);

    $.ajax({
        type: "POST",
        url: "Live.aspx/Decrement",
        data: params,
        contentType: "application/json; charset=utf-8",
        dataType: "json"           
    });
}
chobo
  • 31,561
  • 38
  • 123
  • 191

1 Answers1

0

Incrementing and decrementing in Jquery worked

chobo
  • 31,561
  • 38
  • 123
  • 191