这是我的代码:

<script src="https://sdk.paylike.io/3.js"></script>
<script>
    var paylike = Paylike('***');
    document.querySelector('button').addEventListener('click', pay);

    function pay(){
        paylike.popup({
            // locale: 'da',  // pin popup to a locale
            title: 'Product',
            description: '<?php echo $amount; ?>',
            currency: 'GBP',
            amount: <?php echo $price; ?>,
            // saved on transaction for retrieval from dashboard or API
            custom: {
                // arrays are fine
                products: [
                    // nested objects will do
                ],
            },
            // data from fields will be merged with custom
            fields: [
                // elaborate custom field
            {
                    name: 'name',
                    type: 'name',
                    placeholder: 'John Doe',
                    required: true,
                },

                {
                    name: 'email',
                    type: 'email',
                    placeholder: '[email protected]',
                    required: true,
                },

                {
                    name: 'address',
                    type: 'address',
                placeholder: 'Address',
                    required: true,
                },
                {
                    name: 'postcode',
                    type: 'postcode',
                    placeholder: 'Postcode',

                    required: true,
                },

            ],
        }, function( err, res ){
            if (err)
                return console.log(err);
            console.log(res);



              location.href = 'success.php?e=' + email;
        });
    }
</script>


我希望能够以此弹出表单提交电子邮件,以便将其附加到成功URL上,然后发送电子邮件回执。但是,我尝试执行此操作似乎无效。

这是控制台的输出:

Object
custom: Object
address: "116"
email: "[email protected]"
name: "John Doe"
postcode: "E9 7SR"
transaction: Object
id: "581b23717cb2057463e8d76a"


如何返回电子邮件对象?

在此先感谢您的帮助。

最佳答案

尝试:

res.custom.email


转换为:

location.href = 'success.php?e=' + res.custom.email;


我认为您可能应该使用encodeURIComponent逃脱该值。电子邮件可能不是URL的问题,但我认为这是一个好习惯:

location.href = 'success.php?e=' + encodeURIComponent(res.custom.email);


下次遇到类似问题时,请尝试在代码中放入debugger;(断点)(在此示例中,紧接在}, function( err, res ){之后),在Google Chrome中启动开发人员工具,重新加载,然后脚本将运行,但会在断点,使您可以在该确切点检查变量及其值。

07-28 07:17