I have the following code:
$.ajax({
type: \"POST\",
url: url,
data: sendable,
dataType: \"json\",
success:
The onbeforeunlaod technique does not work for a periodically refreshing page (for example every half seconds). I have figured out that the error caused by refreshing the page can be avoided using delaying the error handling process by a small amount of time.
Example:
$.ajax(...)
.success(...)
.error(function(jqXHR) {
setTimeout(function() {
// error showing process
}, 1000);
});
In addition to that
window.onbeforeunload = function() {//stop ajax calls}
event can be used for less frequently refreshing ajax calls.