In order to code posted by Wiktor (https://stackoverflow.com/a/43338063/7666076) how to pause and resume sending ajax requestes after click on some button (two different buttons like 'pause' and 'play').
Also how to break the current ajax request immediatelly after click on "pause" button. I don't want to wait for new data which will be fetched by ajax query.
Here is my adapted code:
function RefreshData()
{
console.log('Sending AJAX request...');
$.ajax({
type: "GET",
url: "getAjaxRequest.php?"+device+"&callback=?",
dataType: "jsonp"
}).done(function(dataJSON) {
adaptJsonData(dataJSON);
console.log('success');
}).fail(function() {
console.log('error');
}).always(function() {
intervalTime = 100;
console.log('Waiting '+intervalTime+' miliseconds...');
setTimeout(RefreshData, intervalTime);
});
return true;
}
function adaptJsonData(dataJSON) {
# ... some logic with dataJSON object
}