问题 :
- 有一个 Value1 是从 Ajax Function 计算出来的
addToAuthorizeform()
; - 有一个 Value2 是一个 PHP 变量
$amount
。此变量应显示value1
由 Ajax 函数计算的输出。 - 怎么可能?
到目前为止我的代码:
//AJAX FUNCTION THAT OUTPUTS AN AMOUNT
//SEE LINE 24 value="'+arrData[1]+'" <-- This is the correct value that needs to be //output on PHP VARIABLE
<script>
function addToAuthorizeForm() {
$wbc('#slots_purchased').html('');
var new_html = '';
var i = 1;
$wbc('#booking_slots').find('input').each(function () {
if ($wbc(this).attr('checked')) {
var slot_id = $wbc(this).val();
//ajax request to get data
$wbc.ajax({
url: '<?php echo plugins_url('
my_plugin / public ');?>/ajax/getSlotInfo.php?slot_id=' + $wbc(this).val(),
success: function (data) {
arrData = data.split("$");
if (arrData[1] > 0) {
q = 1;
if ($wbc('#seats_' + slot_id).val() != undefined) {
q = $wbc('#seats_' + slot_id).val();
}
new_html += '<input type="hidden" name="x_amount_' + i + '" value="' + arrData[1] + '" />';
$wbc('#slots_purchased').html(new_html);
i++;
}
}
});
}
});
}
</script>
现在 PHP 变量是
$amount = '';
现在我需要知道应该放什么代码,$amount = 1
这样我才能调用或回显在 Javascript 函数的第 24 行计算的 Ajax 相同的值'+arrData[1]+'
。
这是我用来提交的 Authorize.net HTML 表单。
<?php
require_once 'anet_php_sdk/AuthorizeNet.php'; // Include the SDK you downloaded in Step 2
$fname = $bookingReservationObj->getReservationName();
$api_login_id = $bookingSettingObj->getAuthorizeAPI();
$transaction_key = $bookingSettingObj->getAuthorizeTXN();
$amount = // I am not sure what to put here to call Ajax value that i need answer
$fp_timestamp = time();
$fp_sequence = "123" . time(); // Enter an invoice or other unique number.
$fingerprint = AuthorizeNetSIM_Form::getFingerprint($api_login_id,
$transaction_key, $amount, $fp_sequence, $fp_timestamp)
?>
<!-- authorize.net form -->
<form action='https://test.authorize.net/gateway/transact.dll' METHOD='POST' name="authorize_form" style="display:inline">
<!-- Authorize Configuration -->
<input type='hidden' name="x_login" value="<?php echo $api_login_id ?>" />
<input type='hidden' name="x_fp_hash" value="<?php echo $fingerprint?>" />
<input type='hidden' name="x_fp_timestamp" value="<?php echo $fp_timestamp?>" />
<input type='hidden' name="x_fp_sequence" value="<?php echo $fp_sequence?>" />
<input type='hidden' name="x_version" value="3.1">
<input type='hidden' name="x_show_form" value="payment_form">
<input type='hidden' name="x_test_request" value="true" />
<input type='hidden' name="x_method" value="cc">
<input type='hidden' name="x_first_name" value="<?php echo $fname ?>">
<input type='hidden' name="x_last_name" value="<?php echo $fname ?>">
<input type='hidden' name="x_email" value="<?php echo $fname ?>">
<input type='hidden' name="x_phone" value="<?php echo $fname ?>">
<input type='hidden' name="x_description" value="<?php echo 'Cruzz Booking '; ?>">
<!--slots purchased-->
<div id="slots_purchased">
</div>
<input type='hidden' name="x_receipt_link_method" value="link">
<input type='hidden' name="x_receipt_link_text" value="Click here to return to our home page">
<input type='hidden' name="x_receipt_link_URL" value="<?php echo site_url('')."/?p=".$post->ID."&authorize_confirm=1"; ?>">
<input type="hidden" name=" x_cancel_url" value="<?php echo site_url('')."/?p=".$post->ID; ?>">
<input type="hidden" name="rm" value="POST">
</form>
我应该如何开始?