第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過 Ajax 更新 PayPal Smart Button

通過 Ajax 更新 PayPal Smart Button

牛魔王的故事 2023-04-01 16:09:36
我有一個通過 Ajax 更新的購物車(數(shù)量,刪除產(chǎn)品)。如何更新智能按鈕 iframe 中的值?當我刷新頁面時它顯然有效,但是如何使用 Ajax 在后臺進行呢?我嘗試使用繞過同源策略的 hack 重新加載 PayPal iframe,但它沒有用,Smart Button 消失了。這就是我正在談論的技巧:const iframe = document.querySelector("iframe");iframe.src = iframe.src這是我的智能按鈕代碼:<script>     paypal.Buttons({    style: {      shape: "rect",      color: "gold",      layout: "horizontal",      label: "checkout",      size: "responsive",      tagline: "false"  },    createOrder: function(data, actions) {      return actions.order.create({        purchase_units: [{          amount: {            currency_code: "GBP",            value: <?php echo number_format($total, 2); ?>          },        }]      });    },    onApprove: function(data, actions) {      return actions.order.capture().then(function(details) {        alert("Dear " + details.payer.name.given_name + ", Thank you for your payment!");      });    },    onShippingChange: function(data, actions) {      if (data.shipping_address.country_code !== "GB") {        return actions.reject();      }      return actions.resolve();    }  }).render("#paypal-button-container");}</script>
查看完整描述

1 回答

?
千巷貓影

TA貢獻1829條經(jīng)驗 獲得超7個贊

更改此行:


value: <?php echo number_format($total, 2); ?>

要調(diào)用 JavaScript 函數(shù),您需要編寫該函數(shù)并將其作為頁面的一部分


value: getCartTotal()

在某處,也許在 的頂部<script>,您會看到類似以下內(nèi)容的內(nèi)容:


window.myCartTotal = '<?php echo number_format($total, 2); ?>';

function getCartTotal() {

? return window.myCartTotal;

}

然后讓你的 AJAX 也更新 window.myCartTotal


查看完整回答
反對 回復 2023-04-01
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號