function sec() {
$.ajax({
url: 'result.php',
type: "get", //метод отправки
dataType: "html", //формат данных
data: {hash: hash},
success: function(response) { //Данные отправлены успешно
result = $.parseJSON(response);
var ok = result.ok;
},
error: function(response) { // Данные не отправлены
$('#result_form').html('Ошибка. Данные не отправлены.');
}
});
}
setInterval(sec, 1000)
function checkResult() {
const data = {
hash: hash,
}
$.ajax({
url: 'result.php',
dataType: "json",
data: data,
success: (result) => {
const ok = result.ok;
if (ok != 1) {
// перезвоните через секунду
setTimeout(checkResult, 1000);
}
},
error: (response) => { // Данные не отправлены
$('#result_form').html('Ошибка. Данные не отправлены.');
}
});
}
checkResult();