亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

通過 Ajax 更新 PayPal Smart Button

通過 Ajax 更新 PayPal Smart Button

牛魔王的故事 2023-04-01 16:09:36
我有一個通過 Ajax 更新的購物車(數量,刪除產品)。如何更新智能按鈕 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條經驗 獲得超7個贊

更改此行:


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

要調用 JavaScript 函數,您需要編寫該函數并將其作為頁面的一部分


value: getCartTotal()

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


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

function getCartTotal() {

? return window.myCartTotal;

}

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


查看完整回答
反對 回復 2023-04-01
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號