这一直是一个很难搜索的问题,因为所有搜索结果都描述了来自 javascript 的 AJAX 请求。从技术上讲,来自 javascript 的 AJAX 可以解决我的问题,但我更喜欢使用 PHP 纯粹在服务器端解决这个问题。
以下是迄今为止所发生情况的详细说明。我已经简化了很多代码。
客户订单表格.php:
<form action="CreateOrder.php" method="post" onsubmit="this.submitButton.disabled = true;">
<input name="first">
<input name="second">
<button type="submit">Place Order</button>
</form>
创建订单.php
<?php
basicOrderProcesses($_POST['first'],$_POST['second']);
header("Location: PaymentMethod.php?first=$_POST['first']&second=$_POST['second']");
slowOrderProcesses($_POST['first'],$_POST['second']);
die();
function basicOrderProcesses(){
//Code that is absolutely essential to processing payment
}
function slowOrderProcesses(){
//Very time consuming code that I'd rather the customer doesn't have to wait for
}
付款方式.php
<h1>Please Select Your Payment Method</h1>
...
//You get the idea
我认为它工作得很好,但随着slowOrderProcesses()变得更大,代码运行得更慢。slowOrderProcesses()我现在看到它从未在后台运行,并且页面在完成之前不会重定向。
如果 CreateOrder.php 在 JavaScript 中运行,我可以轻松编写一个像这样的AJAX 解决方案。但它是在纯 php 中运行的。等效的 php 解决方案是什么?请记住,当客户选择付款方式时,我需要运行缓慢的流程。(如果客户足够快的话,甚至可能在客户付款后继续运行。)
我希望解决方案不需要太多重写,但我必须做我必须做的事情。(如果可以的话,我会尽量避免安装库。)
烙印99