PHP Ajax Shell Exec() Progress



我要做的事情很简单。

echo "doing a...."
Start progress bar
then exec("commandA")
stop progress bar
echo "doing b...."
Start progress bar
then exec("commandA")
stop progress bar
echo "doing c...."
Start progress bar
then exec("commandC")
stop progress bar

etc

进度栏不需要准确,更舒适地表现出正在发生的事情。

我已经阅读了可以使用jQuery和php/ajax完成。但是我不知道如何做。有人得到一个简单的例子,我可以尝试使用吗?

谢谢:)

最简单的方法是使用twitter bootstrap:
http://twitter.github.com/bootstrap/components.html#progress

这是服务器端部分:

$command = isset($_GET['command']) ? $_GET['command'] : null;
if ($command == null) {
    die("0");
}
echo (int) exec($command);

对于ajax,您可以使用jquery ajax方法,例如 $.get , $.post , $.ajax

$.get('exec.php', { command: 'commandA'}, function(response) {
    if(response == 1) {
        //and you can easily change the width of the progress bar with jQuery:
        $(".bar").css('width', '40%');
    } else {
        alert("The execution got an error!");
    }
}

最新更新