I searched already the stackoverflow website for this solution, but i can't find any solution that fit with my problem.
I'm requesting a API .. but when that api website is offline it need to be abort/timeout that requests.
Any idea how to do that?
Here is my script:
function getStreamDetails() {
$.ajaxSetup({ cache: false });
$.getJSON('https://mywebsite.com/streaminfo.php', function(data) {
var artist = data['song'];
var title = data['song'];
var artistClean = artist.length > 50 ? artist.substring(0, 50) + "..." : artist;
var music = artistClean;
var formattedMusic = music.replace(/;/g, ', ');
var dj = data['live'] == '' ? 'Auto DJ' : data['live'];
$('#dj').html(dj);
$('#listeners').html(data['Plays']);
$('#song').html(formattedMusic);
$('#song').attr('data-original-title', formattedMusic);
});
}
setInterval(getStreamDetails, 60000);
getStreamDetails();
Hope someone can help me out :))