Общем как меня не учи - я делаю так)
function getContent(timestamp) {
toQueryString = function(data) {
var query = '',
i, push = function(key, value) {
query += encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&';
},
key, value;
for (key in data) {
if (!Object.hasOwnProperty.call(data, key)) {
continue;
}
value = data[key];
if ((typeof(data) === "object") && (data instanceof Array)) {
for (i = 0; i < value.length; i++) {
push(key, value[i]);
};
} else {
push(key, data[key]);
};
};
return query.replace(/&$/, '').replace(/%20/g, '+');
};
var queryString = {
'timestamp': timestamp
};
var result = fetch('server.php', {
method: 'post',
headers: {
"Content-type": "application/x-www-form-urlencoded"
},
body: toQueryString(queryString)
})
result.then(function(response) {
return response.json()
}).then(function(text) {
document.querySelector('#response').innerHTML = text.data_from_file;
getContent(text.timestamp);
})['catch'](function(ex) {
getContent(timestamp);
})
}