PHP运行外部命令并在完成时重定向


PHP run external command and redirect when finished

我正在构建一个主页,在用户填写表单后,我需要运行一个相当长的PHP脚本(填充我的数据库)。因此,我试图在脚本运行时显示一个加载页面,并在完成后重定向到其他页面。

我目前正在做:

表单中.php

<form method="post" action="load.php">
....
</form>

load.php有加载页面:

<?php
ob_start();
?>
<!DOCTYPE HTML>
<html>
...loading page here...
</html>
<?
ob_end_flush();
include 'add.php';
?>

在这里,我希望显示带有ob_start和ob_end_flush的页面,并开始脚本。

在add.php的末尾,我做

header('Location: redirect_to_here.php');
jQuery.post({
         url:    'http://example.com/save.php',
         data: { 'name':'name'
              },
      beforeSend:function(){
         $(".loading_msg").show();
    },
         success: function(result) {
         $(".loading_msg").hide();
                      if(result.isOk == false)
                          alert(result.message);
                  },
         async:   false
    }); 

使async为false,在发送数据之前显示div,成功之后隐藏