如何在PHP变量中传递javascript
我正在编写Authorize.net表单提交如何在PHP变量中传递javascript,php,javascript,authorize.net,Php,Javascript,Authorize.net,我正在编写Authorize.net表单提交 $api_login_id = $bookingSettingObj->getAuthorizeAPI(); // works $transaction_key = $bookingSettingObj->getAuthorizeTXN(); // works $amount = /* What should i put here so i can echo the final price that is calculated by
$api_login_id = $bookingSettingObj->getAuthorizeAPI(); // works
$transaction_key = $bookingSettingObj->getAuthorizeTXN(); // works
$amount = /* What should i put here so i can echo the final price that is calculated by Javascript Function : addToAuthorizeForm(); ????? */
价格计算是通过javascript函数addToAuthorizeForm完成的。
请让我知道我应该添加什么代码,以便javascript函数“addToAuthorizeForm”能够成功响应
更新:
我已经在使用Ajax了。下面是我正在使用的javascript函数。我只需要知道我放了什么代码来执行这个javascript函数,并给出最终的价格
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="item_name_'+i+'" value="'+arrData[0]+'" /><input type="hidden" name="amount_'+i+'" value="'+arrData[1]+'" /><input type="hidden" name="quantity_'+i+'" value="'+q+'" />';
$wbc('#slots_purchased').html(new_html);
i++;
}
}
});
}
});
}
函数addToAuthorizeForm(){
$wbc(“#购买的插槽”).html(“”);
var new_html='';
var i=1;
$wbc(“#预订#U插槽”)。查找('input')。每个(函数(){
if($wbc(this).attr('checked')){
var slot_id=$wbc(this.val();
//获取数据的ajax请求
$wbc.ajax({
url:'/ajax/getSlotInfo.php?slot_id='+$wbc(this.val(),
成功:功能(数据){
arrData=data.split($);
如果(arrData[1]>0){
q=1;
if($wbc('#seats_u'+slot_uid).val()!=未定义){
q=$wbc('#seats_uu'+slot_uid).val();
}
新的html+='';
$wbc(“#购买的插槽”).html(新的#html);
i++;
}
}
});
}
});
}
您不能在服务器端PHP代码中调用JS函数
尝试在PHP端实现相同的逻辑并调用该函数
<?php
function addToAuthorizeForm () {
.
.
Add the Same logic that you have put in the JS function
.
.
}
$amount = addToAuthorizeForm();
?>
将所需参数传入函数并获取封装逻辑的输出。您必须使用ajax。为什么需要这样做?通常,服务器计算,javascript使用。看看你是否可以稍微改变一下你的逻辑你不应该计算服务器端而不是客户端的“最终价格”吗?如果您依赖客户端代码来计算价格,那么用户可以自己定价。@Jessica如何在PHP变量中传递javascript???如果我放在下面,这段代码将无法工作,因为它是javascript函数