如何从具有属性的javascript运行外部javascript并获取对象

问题描述

这是打开窗口并要求提供信用卡信息的代码。 但是我必须先打开一个网页,这是我不想要的。

echo '<script src="https://evopaymentsmexico.gateway.mastercard.com/checkout/version/57/checkout.js" data-error="errorCallback" data-cancel="cancelCallback"></script>';
echo '<script type="text/javascript">
                function errorCallback(error) {
                      console.log(JSON.stringify(error));
                }
                function cancelCallback() {
                      console.log("Payment cancelled");
                }
                Checkout.configure({
                  session: { 
                    id: "' . $sessionid . '"
                    },interaction: {
                        merchant: {
                            name: "Your merchant name",address: {
                                line1: "200 Sample St",line2: "1234 Example Town"            
                            }    
                        }
                   }
                });
                Checkout.showLightBox();
</script>';

我正在尝试直接在javascript而不是PHP上运行代码。 因此,我不会打开其他页面

问题是从未创建“ Checkout”对象。

这是我的代码

var scriptTag = document.createElement("script");

    scriptTag.setAttribute("data-error","errorCallback");
    scriptTag.setAttribute("data-cancel","cancelCallback");

    scriptTag.src = "https://evopaymentsmexico.gateway.mastercard.com/checkout/version/57/checkout.jss";
    //eval(scriptTag);     it doesn't work,Checkout object is not created.
    document.body.appendChild(scriptTag);   it doesn't work either,same thing.

    function errorCallback(error) {
        console.log(JSON.stringify(error));
    }
    function cancelCallback() {
        console.log("Payment cancelled");
    }
    Checkout.configure({
        session: {
            id: "' . sessionid . '"
        },interaction: {
            merchant: {
                name: "Your merchant name",address: {
                    line1: "200 Sample St",line2: "1234 Example Town"
                }
            }
        }
    });
    Checkout.showLightBox();

感谢您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)