There is a function that draws a graph of the resulting array using AJAX.
// ********************************** startUpdate ******************************** // function startUpdate() { fetchData(); data = []; alreadyFetched = {}; $('#average').hide(); var currentTemperatureHolder = $('.currentTemperatureHolder'); function fetchData() { function beforeSendFunc() { tempSpan.hide(); lastUpdateTimeHolder.hide(); preloaderHolder.show(); } function completeFunc(answer_code) { if(answer_code.responseText === 'DATA IS EMPTY') { alert('Данные отсутствуют'); return; } } function showData() { tempSpan.show(); lastUpdateTimeHolder.show(); preloaderHolder.hide(); return true; } function onDataReceived(series) { $('.tempSpan').text(series[+series.length - 1][1]); var lastUpdateTime = new Date(+series[+series.length - 1][0] - 10800000); var hours = lastUpdateTime.getHours() < 10 ? '0' + lastUpdateTime.getHours() : lastUpdateTime.getHours(); var minutes = lastUpdateTime.getMinutes() < 10 ? '0' + lastUpdateTime.getMinutes() : lastUpdateTime.getMinutes(); var seconds = lastUpdateTime.getSeconds() < 10 ? '0' + lastUpdateTime.getSeconds() : lastUpdateTime.getSeconds(); var lastUpdateTime = hours + ':' + minutes + ':' + seconds; $('.lastUpdateTime').text(lastUpdateTime); showData(); data = [ series ]; $.plot("#placeholder", data, options); } $.ajax({ url: './getTemperature.php', beforeSend: beforeSendFunc, complete: completeFunc, success: onDataReceived }); } setInterval(fetchData, 5000); } I want in this function displays the time before the update, that is, displays in the timer 5, 4, 3, 2, 1 - the Ajax request went, arrived, brought the data, and went 5, 4, 3 ...
Tried it differently, but the number of calls to the timer function is growing exponentially. From the example, removed the timer function so as not to frighten the public.
I would be grateful for the correct decision and even a hint.