Пробрасываю переменную stopInterval в getCheck. Почему не останавливается setInterval?
function getCheck(urlSend, stopInterval) {
let getPhone = $('#phone').val();
let replace = getPhone.replace(/\D+/g, "");
let phone = replace.replace('380', '+380');
let objInterval = {
'phone': phone
};
$.ajax({
type: "POST",
url: '/vipapi/check_verification/',
dataType: 'json',
data: objInterval,
beforeSend: function (jqXHR, settings) {
urlSend = settings.url;
},
success: function (res) {
let table = $('#verificationResult').DataTable();
table.clear().draw();
if (res.length > 0) {
let newData = res.map(function (r) {
let resp = {
"<?= lang("data")?>": r.date,
"<?= lang("phone_number")?>": r.phone,
"<?= lang("status_verification")?>": create_resp(r.resp)
}
return resp;
});
table.rows.add(newData);
table.draw();
let firstObj = res[0];
if (firstObj.resp !== null || firstObj.resp !== 'ok') {
console.log('Не работает')
clearInterval(stopInterval);
}
}
},
error: function () {
$('.service-error').modal('show');
setTimeout(function () {
$('.service-error').modal('hide');
logFile(urlSend);
}, 3000)
}
});
}
$(function () {
"use strict";
let stopInterval = 0;
$('#history_verification').on('click', function (e) {
e.preventDefault();
let urlSend = '';
if (stopInterval !== 0) {
clearInterval(stopInterval);
}
getCheck(urlSend, stopInterval);
});
$(":input").inputmask();
$.validator.addMethod("minlengthphone", function (value) {
return value.replace(/\D+/g, '').length > 11;
});
$("#verification").validate({
rules: {
phone: {
required: true,
minlengthphone: true
}
},
messages: {
phone: "<?= lang("correct_phone_number")?>...",
},
errorLabelContainer: '.err',
submitHandler: function () {
if (stopInterval !== 0) {
clearInterval(stopInterval);
}
let getPhone = $('#phone').val();
let replace = getPhone.replace(/\D+/g, "");
let phone = replace.replace('380', '+380');
let obj = {
'ref': $('.csrf').val(),
'phone': phone
}
let urlSend = '';
$.ajax({
type: "POST",
url: '/verificationForm',
dataType: 'jsonp',
data: obj,
beforeSend: function (jqXHR, settings) {
urlSend = settings.url;
},
success: function (res) {
$('.csrf').val(res.csrf);
saveCsrf(res.csrf);
$('.verified-success').modal('show');
setTimeout(function () {
$('.verified-success').modal('hide');
getCheck();
}, 3000);
stopInterval = setInterval(getCheck, 10000);
},
error: function () {
$('.service-error').modal('show');
setTimeout(function () {
$('.service-error').modal('hide');
logFile(urlSend);
}, 3000)
}
});
}
});