The following runs every 7 second and calls the showAlert() function. It looks if finds any data through the database. My question is how can I stop it if it finds any data? So there is no need to run again and again.
setInterval(function myalert() {
$.getJSON("handler.php?type=alert&callback=?&cookie="+ y, showAlert);
}, 7000);
on backend this is a part of the php
$alertGroup = mysql_fetch_array($alertQuery);
$json[] = array($title,$text);
echo $callback . "(" . json_encode($json) . ")";
this is the showAlert
function showAlert(data) {
console.log(data[0][0]);
console.log(data[0][1]);
}