dro59505 2013-06-12 14:35
浏览 34

如何在PHP变量中传递javascript [复制]

This question already has an answer here:

I am working on a Authorize.net form submit.

$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(); ????? */ 

and the price calculation is done by javascript function addToAuthorizeForm. Please let me know what code should i add so the javascript funcrtion "addToAuthorizeForm" can echo succesfully..

UPDATE :

I am already using Ajax. Here is the javascript function i am using. I just need to know what code i put to execute this javascript function and echo final price..

    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++;
                      }
                  }
                });

            }

        });

    }
</div>
  • 写回答

1条回答 默认 最新

  • douxu5845 2013-06-12 14:47
    关注

    You can't call JS function in side the server side PHP code.

    Try to implement the same logic in PHP side and call that function

    <?php 
    function addToAuthorizeForm () {
    .
    .
    Add the Same logic that you have put in the JS function
    .
    .
    }
    
    $amount = addToAuthorizeForm();
    ?>
    

    Pass required parameters in to the function and get the out put encapsulating the logic.

    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示