0

I am using AJAX to load content from a PHP file into a div every 5 seconds. This works fine, but I would like to refresh the browser if the contents of the div are equal to "Your item has expired."

Here is my HTML:

<div id="tableHolder"></div>

Here is my JS:

 $(document).ready(function(){
  refreshTable();
});

function refreshTable(){
    $('#tableHolder').load('ajax_time.php', function(){
       setTimeout(refreshTable, 5000);
    });
}

I think I can use something like:

if (document.getElementById('tableHolder').innerHTML == "Your item has expired.")

But I'm not sure how to go about putting it together. Any ideas?

4

1 回答 1

3

You can do this

$('document').ready(function(){
    refreshTable();
});


function refreshTable(){
       if($("#tableHolder").text() == "Your item has expired."){
         location.reload();
       } 
   $('#tableHolder').load('ajax_time.php', function(){
      setTimeout(refreshTable, 5000);
   });
}
于 2013-03-31T03:35:32.007 回答