I am trying to make a dynamic dashboard that refreshes every x seconds to deliver new data from a PHP file. I want this to issue an Alert whenever there is a change in the data delivered, not whenever the data is refreshed. I am using require.js, watch.js and jQuery. I can`t get it to issue alert on changes on #tfpromo or the variable refreshId. Is there a way to do this in jQuery, JS or Watch.js?
PHP file:
$mainbalance = "foo";
echo $mainbalance;
Index.html:
<div id="tfpromo"></div>
<script>
require(['watch', 'jquery'], function(WatchJS, $) {
var watch = WatchJS.watch;
var unwatch = WatchJS.unwatch;
var callWatchers = WatchJS.callWatchers;
$(document).ready(function () {
$("#tfpromo").load("php/dataload.php");
var refreshId = setInterval(function load2(){
$("#tfpromo").load("php/dataload.php");
}, 4000);
watch(refreshId, function(){
alert("balance changed!");
});
});
});
</script>
watch.jsis for detecting changes to JavaScript objects, not DOM elements.