使用passthrough将ajax结果中的变量发送到php
Send Variables from ajax results to php with a 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'];
我遇到的问题是,这需要太长时间,所以我想像在其他领域一样使用passthrough文件,但无法弄清楚如何"passthrough"值这是我的passthrough 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]);
以获取参数。
相关文章:
- 将PHP变量传递给jQuery时遇到问题
- 通过javascript重定向html传递php变量
- 如何在php变量中嵌入JQuery代码
- 在javascript函数中使用php变量
- 将地理编码结果转换为php变量以发布到mysql数据库
- JavaScript,PHP-用JavaScript将多个数据库记录发送到变量或表
- 如何将变量php传递给javascript
- 显示动态变量(php和javascript)的总数
- 传递变量PHP、Javascript location.reload和HTML输入
- 需要将变量 php 的值传递给 javascript,但我不能
- 将变量从 .html 传递到太大而无法容纳在 URL 中的变量.php
- 如何在函数中传递javascript中的变量php
- 在Jquery中插入变量PHP
- 选择正确的变量 php/javascript
- 将HTML存储在变量PHP中,然后回显它
- 将变量PHP Smarty传递给Javascript
- 传递HTML表单post数据到不同的文件/网页javascript变量(php)
- 问题与传递变量(php, sql, jquery拖拽)
- 设置PHP中的javascaript变量(PHP在javascript中)
- 将变量php问题化为代码jquery