Possible Duplicate:
jQuery refresh if PHP file echo's 'true'
I have the following div on my index:
<div id='tv'> <? include 'tv.php' ?> </div>
I have a script that changes content in tv.php and returns ‘true’ at a certain time called checktime.php.
I’m trying to have jQuery in the index header to check the PHP page every 10 seconds and if checktime.php returns ‘true’ jQuery ‘refreshes’ the content of the #tv div. This is the code I currently have but it’s not working. It seems to check checktime.php but the div doesn’t automatically refresh.
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
setInterval("checkTime()", 10000);
function checkTime(){
$.ajax({
url: 'checktime.php',
success: function(refresh){
if($.trim(refresh) == "true"){
$('#tv').load('tv.php');
}
}
});
}
});
</script>
See if this works better for you, you need to adjust SetInterval to work with jQuery: