Вы можете использовать LocalStorage API для достижения этой цели.
Когда пользователь отправляет форму, вы сохраняете состояние в LocalStorage, который управляет атрибутом отключенных кнопок отправки.При загрузке страницы вы должны запросить LocalStorage
для этого состояния и соответственно инициализировать отключенный атрибут:
// Query storage state and set disabled attribute if local storage has
// myBtnDisabled key value of "true"
if(window.localStorage && localStorage.getItem("myBtnDisabled") === "true") {
document.getElementById("myBtn").disabled = true;
}
function loadDoc(dataset_id) {
var xhttp = new XMLHttpRequest();
document.getElementById("myBtn").disabled = true;
// Set state to cause the button to be disabled in future refreshes
if(window.localStorage) {
localStorage.setItem("myBtnDisabled", "true");
}
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("POST", "http://127.0.0.1:8000", true);
xhttp.setRequestHeader('Accept', 'text/html')
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("Content-Length", "22");
xhttp.send(JSON.stringify({
'operation': 'inactive'
}));
}