dscrn1974 2014-11-17 09:23
浏览 54
已采纳

将jQuery变量解析为PHP表单到PSP购物卡

I have to parse this jQuery output <span id="chargetotal" class="chargetotal">Amount</strong></span> to a PSP shopping card page.

From this page i try to parse the 'Total amount' (Quantity * Value), and the rest of the form variables to the PSP shopping card page (https://test.ipg-online.com/connect/gateway/processing).

On the voucher page i include ipg-util.php which look like this:

<?php
$dateTime = date("Y:m:d-H:i:s");
    function getDateTime() {
        global $dateTime;
        return $dateTime;
    }
    function createHash($chargetotal, $currency) {
        $storeId = "XXX storeId XXX";
        $sharedSecret = "XXX sharedSecret XXX";
        $stringToHash = $storeId . getDateTime() . $chargetotal .
        $currency . $sharedSecret;
        $ascii = bin2hex($stringToHash);
        return sha1($ascii);
    }
?>

In this instruction i setup 3.3 PHP Example

The form look like this:

        <form method="post" action="https://test.ipgonline.com/connect/gateway/processing">

            <input type="hidden" name="txntype" value="sale">
            <input type="hidden" name="timezone" value="GMT"/>
            <input type="hidden" name="txndatetime" value="<?php echo getDateTime() ?>"/>
            <input type="hidden" name="hash" value="<?php echo createHash( "13.00","978" ) ?>"/>
            <input type="hidden" name="storename" value="XXX My store id XXX"/>
            <input type="hidden" name="mode" value="fullpay"/>
            <input type="text" name="chargetotal" value="13.00"/>
            <input type="hidden" name="currency" value="978"/>
            <input type="hidden" name="responseSuccessURL" value="http://www.abbeyglen.ie/abbeyglen-castle-hotel/voucher-succes.html"/>
            <input type="hidden" name="responseFailURL" value="http://www.abbeyglen.ie/abbeyglen-castle-hotel/voucher-failure.html"/>
            <input type="submit" value="Submit">
        </form>

My problem is that in the above form example they use a strict value of 13.00 for <input type="text" name="chargetotal" value="13.00"/> to create the hash 'form variable'.

But in my case chargetotal is the 'Total amount' of the jQuery function in this HTML <span id="chargetotal" class="chargetotal">Amount</strong></span> .

See below, the jQuery script to get the 'Total amount'.

                 <script type="text/javascript">
                        $(document).ready(function(){

                        update_amounts();
                        $('.qty').change(function() {
                            update_amounts();
                        });
                    });

                    function update_amounts()
                    {
                        var chargetotal = 0;
                        var sum = 0.0;
                        $(function () {
                            var qty = $(this).find('.qty').val();
                            var price = $(this).find('.price').val();
                            var chargetotal = (qty*price)
                            sum+=chargetotal;
                            $(this).find('.chargetotal').text(''+chargetotal);
                        });

                    }
                </script>

How do i translate the jQuery 'Total amount' to a <input type="text" name="chargetotal">?

Thanks!

  • 写回答

1条回答 默认 最新

  • du4629 2014-11-17 10:56
    关注

    Add

    <input type="hidden" name="chargetotal" id="chargetotal" value=""/>
    

    to your form. Remove id="chargetotal" from

    <span class="chargetotal" id="chargetotal"></span>
    

    Add

    $('#chargetotal').val(chargetotal);
    

    after

    $(this).find('.chargetotal').text(''+chargetotal);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建