我需要find_optimal_schedule()每 5 秒运行一次函数,同时每次更新 DIV 容器schedule。下面是我的代码片段。问题是alert("Init")执行,而alert("True")或alert("False")不执行。FireBug 显示optimize.php每 5 秒运行一次,但我不明白为什么 DIV 容器的内容一直保持空白。
PS 代码gantt.php工作正常,因为我在没有计时器的 DIV 容器中对其进行了测试,并且甘特图显示正确。因此,我在这里不提供此代码,因为事实并非如此。
调度程序.php
<script>
window.setInterval(function(){                 
     find_optimal_schedule();
}, 5000);
</script>
<script>
function find_optimal_schedule() {
    $.ajax({
        url: 'modules/mod_scheduler/pages.php?page=optimize.php',
        dataType: 'json',
        success: function(output){
            alert("Init");
            if(output.msg === 1){
                alert("True");
                $('#schedule').html(output.html);
            } else {
                alert("False");
                return false;
            }
        }
    });
}
</script>
<div style="width:100%; height:350px; position:relative" id="schedule" class="schedule"></div>
pages.php
<?php
    @session_start();
    @$pag_mod = $_GET['pag_mod'];
    if(!isset($pag_mod))
        $pag_mod = 0;
    if (isset($_GET['pag_mod'])) {
        include 'modules/mod_scheduler/'.$_GET['pag_mod'];
    }
    else {
        include 'modules/mod_scheduler/scheduler.php';
    }
?>
优化.php
<?php
//  Dispay Gantt chart
$html_code = '<img src="modules/mod_scheduler/gantt.php">';
echo json_encode(array('msg' => 1, 'html' => $html_code)); 
?>