Inigo Inigo - 5 months ago 28
Java Question

How to send an alert/alarm in a jsp on sql insert

When customer makes a deposit, this inserts a request in the database. When this happens, I want send an alert or play an alarm on a separate jsp (admin page containing list of approvals). Any ideas?

Answer

In case anyone is interested, I solved this by creating a polling function that runs on the header that sits on all pages via tiles framework.

var alert = document.createElement('audio');
var count2 = $.cookie('list');
function poll(){
  setTimeout(function(){
    $.ajax({
        url: url
        ,type: "GET"
        ,success: function(data){
            var count1 = data.info;
            if(count1>count2){
                count2 = count1;
                alert.play();
                $.cookie("list",count2,{path:'/'});
                $("#approvalCount").html($.cookie("list"));
            }else if(count1<count2){
                count2 = count1;
                $.cookie("list",count2,{path:'/'});
            }
        }
        ,dataType: "json"
        ,complete: poll
        ,timeout: 2000
    })
}, 30000);

};

Comments