Untitled

 avatar
unknown
javascript
2 years ago
1.3 kB
14
Indexable
$(document).ready(function () {
    let timerId = setTimeout(function tick() {
        getAds();
        timerId = setTimeout(tick, 2000);
    }, 2000);
});

function getAds() {
    $.ajax({
        url: '/ads/get',
        method: 'post',
        dataType: 'json',
        data: {limit: 100},
        success: function (data) {
            updateAdsTable(data);
        },
        error: function (jqXHR, exception) {
            if (jqXHR.status === 0) {
                alert('Ошибка: Not connect. Verify Network.');
            } else if (jqXHR.status == 404) {
                alert('Ошибка: Requested page not found (404).');
            } else if (jqXHR.status == 500) {
                alert('Ошибка: Internal Server Error (500).');
            } else if (exception === 'parsererror') {
                alert('Ошибка: JSON parse failed.');
            } else if (exception === 'timeout') {
                alert('Ошибка: Time out error.');
            } else if (exception === 'abort') {
                alert('Ошибка: Ajax request aborted.');
            } else {
                alert('Ошибка: Uncaught Error. ' + jqXHR.responseText);
            }
        }
    });

    return true;
}
Editor is loading...