i wrote web method called on unload event of jquery. running when run through visual studio. deployed in iis. working when execute application in ie , firefox. when run application in chrome, strangely doesn't fire unload event. below have written:
<script type="text/javascript" language="javascript"> var starttime; $(window).load(function () { starttime = new date().gettime(); }); $(window).unload(function () { var endtime = new date().gettime(); var diff = new date(endtime - starttime); var path = window.location.pathname.tostring(); $.ajax({ type: "post", url: path + "/loguseractivity", data: "{ 'timespent': '" + math.floor(diff / 1000).tostring() + "', 'urlvisited': '" + path + "'}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function () { }, error: function (xhr, status, error) { }, failure: function () { } }); }); </script>
credit goes @daniel a. white
it not issue jquery unload ajax sync call.
made ajax call sync instead of async, worked on chrome other browsers.
$.ajax({ async: false, type: "post", url: path + "/loguseractivity", data: "{ 'timespent': '" + math.floor(diff / 1000).tostring() + "', 'urlvisited': '" + path + "'}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function () { }, error: function (xhr, status, error) { var err = eval("(" + xhr.responsetext + ")"); alert(err.message); }, failure: function () { } });
Comments
Post a Comment