javascript - 使用 passthru 将变量从 ajax 结果发送到 php

标签 javascript php jquery ajax passthru

我有一个 PHP 文件,当选中复选框并单击按钮时,将调用包含以下代码的 js 文件

$.ajax ({
    type: "POST",
    url: "decisionExec.php",
    dataType: "json",
    data:({cnt:cnt,amGuide:guides.amGuide,folGuide:guides.folGuide,tichGuide:guides.tichGuide,nebGuide:guides.nebGuide,sterGuide:guides.sterGuide,ingGuide: guides.ingGuide }),
    success: function(data) {
        $("#message").html(data.message);//"Generating the files for the BookScouter results.  An email will be sent when this is completed."
        $("#start2").html(data.start);
    } // end of success

}); // end of ajax

这段代码工作正常,并使用 POST 将正确的数据发送到我的 php 文件

 $amG        = $_POST['amGuide'];
 $folG       = $_POST['folGuide'];
 $tichG      = $_POST['tichGuide'];
 $nebG       = $_POST['nebGuide'];
 $sterG      = $_POST['sterGuide'];
 $ingG       = $_POST['ingGuide'];

我遇到的问题是这需要太长时间,所以我想像在其他区域一样使用直通文件,但无法弄清楚如何“直通”这些值 这是我的 passthru php 文件。

 <?php
 passthru('php /decision.php >> /web/webInv.txt &');
 $now = date("m/d/y h:i:s");
 $message = array('message' => 'An email will be sent when it is finished.',
             'start' => 'Started at approx. ' . $now);
 echo json_encode($message);
 ?>

关于如何做到这一点的任何想法(此文件需要大约 30 分钟来处理和通过电子邮件发送)

最佳答案

我猜您是在问如何将所有 POST 参数发送到 decision.php。您可以使用 serialize()json_encode() 序列化它们,并将其作为命令行参数发送到脚本。

$args = escapeshellarg(serialize($_POST));
shell_exec("php /decision.php $args >> /web/webInv.txt 2>&1 &");

使用 passthru 是没有意义的,因为输出被重定向,所以没有任何东西可以传递给客户端。

decision.php中,使用:

$_POST = unserialize($argv[1]);

获取参数。

关于javascript - 使用 passthru 将变量从 ajax 结果发送到 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36345712/

相关文章:

php - CURL - 此请求需要 HTTP 身份验证

javascript - Jquery 带条件选择选项

jquery - KendoUI 可调整大小的小部件?

javascript - 如何使用angularjs从 Controller 获取数据到mvc中的$scope

javascript - JavaScript/jquery 中的内存泄漏在哪里?

php - 如何左连接两个表并显示信息?

javascript - 如何根据月份中的数字获取日期名称

jquery - IE再次失效,jQuery滚动震动剧烈

javascript - 输入 :Checked jQuery vs CSS?

javascript - 成功刷新页面