Home » Php » php – JQuery wallboard with sound notifications and flashing div/table cells

php – JQuery wallboard with sound notifications and flashing div/table cells

Posted by: admin July 12, 2020 Leave a comment


I have a page with SQL Queries on inside a table which show results on a large screen.

I then browse to index.php which contains this code:

// <![CDATA[
$(document).ready(function() {

    // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
    $.ajaxSetup({ cache: false });    
    setInterval(function() {
    }, 2000); // the "2000" here refers to the time to refresh the div. it is in milliseconds.
// ]]>


<div class="container"><h3>Loading Data...</h3></div>

So it loads this page constantly.

What i would like to do is have it so if any of the queries contain data that needs to have action taken on it, the table cell will flash 2 colours and also a sound will play every 5 minutes.

What would be the best way to do this and keep the constant page load?

How to&Answers:

I would change the .load() into an ajax call, which calls a function when done. Check the script below:

// Prepare the audio - replace the link with your own mp3
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'http://www.uscis.gov/files/nativedocuments/Track%2090.mp3');

// Global that will control the flashing / playing of sound
var alertUser = false;
$(document).ready(function() {
    $.ajaxSetup({ cache: false });      // Fix IE bug
            url: "data.php",
            complete: function( jq, content ){
                $('.container').html( jq.response );
                if( jq.response.indexOf( 'from' ) != -1 ) { // your logic goes here to decide the warning
                    alertUser = true;
                } else {
                    alertUser = false;
    }, 2000);

        if( alertUser ) {
            // play tune

            // flash background
            window.setTimeout( function(){
            }, 200 );
            window.setTimeout( function(){
            }, 400 );
            window.setTimeout( function(){
            }, 600 );
    }, 1000);