Я создаю систему, которая, когда пользователь хочет обновить sh страницу onbeforeunload
функцию, вызывает ajax функцию.
когда ajax процесс завершен, я вызываю для изменения windows местоположения.
, но когда windows изменение местоположения onbeforeunload
снова вызывает ajax функцию.
я хочу отменить onbeforeunload
, когда я хочу изменить местоположение и работать, когда пользователь хочет обновить sh стр.
onbeforeunload
код функции
window.onbeforeunload = function() {
window.setTimeout(function () {
quiz.saveData(id);
}, 0);
window.onbeforeunload = null;
}
ajax
функция
Quiz.prototype.saveData = function(id){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert(this.responseText);
window.location = "http://users/" + id;
}
};
xhttp.open("POST", "http://localhost/saveData", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send();
}