1 回答

TA貢獻1876條經驗 獲得超7個贊
PHP 只能在服務器上看到。因此,您應該使用fetch(推薦)或XMLHTTPRequest向服務器發(fā)送一個值。
創(chuàng)建一個 PHP 文件,您可以在其中接收$_GET或$_POST變量并處理剩余的付款。在本例中,我將文件ajax_file.php命名為 ,但您可以隨意命名它。
添加fetch到您的onApprove方法中。我們將使用該POST方法發(fā)送,以便通過該body屬性發(fā)送數(shù)據(jù)更容易一些。GET也可以這樣做,但工作方式有點不同。
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
// URL which to send the value to.
const url = 'http://yoursite.com/ajax_file.php';
// Message to send. In this example an object with a state property.
// You can change the properties to whatever you want.
const message = { status: 'success' };
// Send it to the URL with the POST method
// and send the message in JSON format.
fetch(url, {
method: 'POST',
body: JSON.stringify(message)
}).catch(function(error) {
console.log(error); // Display error if there is one.
});
});
}
在您的 PHP 文件中,例如ajax_file.php.
在那里你檢查價值。查看它是否已發(fā)送以及它是否是正確的值,然后從那里繼續(xù)流程。
// Check if status send.
$status = isset( $_POST[ 'status'] ) ? $_POST[ 'status' ] : false;
// Check the value of status
if ( $status === 'succes' ) {
// Status is a success.
// Continue your form flow.
}
您的問題不清楚接下來會發(fā)生什么,但我希望您能從這里弄清楚。
- 1 回答
- 0 關注
- 161 瀏覽
添加回答
舉報