PHP的Ajax壳牌执行exec()的研究进展研究进展、壳牌、PHP、Ajax

2023-09-10 18:13:11 作者:-/不管怎样活着就好

我试图做的是很简单的。

What I'm trying to do is quite simple.

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

进度条并不需要准确,更多的是一种安慰,显示有事情发生。

The progress bar doesn't need to be accurate, more of a comfort to show something is happening.

我读过它可以使用jQuery和PHP / AJAX做..但我不知道怎么样。 任何人有一个简单的例子,我可以尝试用工作?

I've read it can be done using jquery and php/ajax.. but I've no idea how. Anyone got a simple example I can try a work with ?

感谢:)

推荐答案

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

The simplest way is to use 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,$。员额,$就

for ajax you can use jQuery ajax methods like $.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!");
    }
}