weixin_33739523 2012-11-06 12:44 采纳率: 0%
浏览 89

PHP Ajax Shell Exec()进度

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

etc

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

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 ?

Thanks :)

  • 写回答

1条回答 默认 最新

  • weixin_33671935 2012-11-06 12:54
    关注

    The simplest way is to use twitter bootstrap:
    http://twitter.github.com/bootstrap/components.html#progress

    This is the server side part:

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

    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!");
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?