loopsasynchronouscoldfusionrefreshcfquery

Coldfusion - Refreshing Page When A Database Record Updates


Good day,

Let me describe my problem :

Scenario :

Problem :

Solution :


Solution

  • Can be done through sockets, and you do not have to check the availability of a new record every minute.

    You can also do it with javascript/jquery:

    <script>
    var lastAlert = '#lastAlert#'; //last at the time of loading the page
    
    setInterval(function() {
        lastAlert = isUpdated(lastAlert);
    }, 60000);
    
    function isUpdated(lastAlert){
    res = lastAlert;
    $.ajax({                            
        url: 'checkAlerts.cfm', //in this file do check for changes in the database. should return the number of the last alert
        type: 'POST',
        data: {lastAlert:lastAlert},
        cache: false,
        success:function(res){  
            if(res > lastAlert){
                //your code if there is a new entry 
                alert('a new entry has been added');
            }
        }
    });
    return res;
    }   
    </script>
    

    I did not check the code! But I hope you understand how to proceed.