我的功能有问题。 我想每5秒刷新一次这个功能而不刷新页面!
这是在refresh.php:
if ($files_count == 0) { ?> <img src="img/upload.gif"> <?php }
,这是在index.php:
<?php include 'refresh.php'; ?>
怎么做? :d
编辑:
答案 0 :(得分:0)
<强> HTML 强>
<div class="container"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<强>的JavaScript 强>
setInterval(function(){check_files();}, 5000);
function check_files() {
$.ajax({
url: 'path/to/php/file.php',
type: 'GET',
cache: false,
data: {},
success: function (resp) {
if (resp == 0) {
$('.container').html('<img src="img/upload.gif" />');
}
else {
/// Something else
}
}
});
}
<强> PHP 强>
<?php
$count = count(glob("your_directory/*",GLOB_BRACE)); // This is what I assume you're counting files with. You may be counting from a database, though.
echo $count; // This goes back to the AJAX call.