Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

102
Views
ajax file updater to check last modified time for a file then refresh

i have some code which i would like to update (refresh) if my file has been modified since and its on a loop so it would keep trying to push it though can some1 please help me make it work? here's the code;

 <script>
 
 
 var checkUrl="messages.php";
    window.setInterval("checkForUpdate()", 1000);
    var pageLoad = new Date().getTime();

    function checkForUpdate() {
        $.ajax(checkUrl, {
            type : 'HEAD',
            success : function (response, status, xhr) {
                if(firstCheck === false) {
                    firstCheck = true;
                    return;
                }
          
                var lastModified = new Date(xhr.getResponseHeader('Last-Modified'))
                    .getTime();
                if(lastModified > pageLoad) {
                  window.location.replace("./");

                }
            }
        }); 
    }  
 
 </script>
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs