【问题标题】:How to avoid ajax sending multiple times to server in woocommerce?如何避免 ajax 多次发送到 woocommerce 中的服务器?
【发布时间】:2019-02-04 19:41:42
【问题描述】:

我在 woocommerce 中开发了自定义网关插件。我正在通过 jquery ajax 提交订单并通过成功事件获得响应并处理付款。在提交 ajax 时向 3rd 方服务器提交多次。如何避免它。

function payment_field(){ ?>
<script>
var success = function(response){
jquery.ajax({
handle the response through ajax and redirect the page
})
}

 jQuery("form.woocommerce-checkout").on('submit', function (e) {
//submitinfo to the server
//Pblm with sending multiple times to server
 }

please check with the image

【问题讨论】:

  • 函数体中的&lt;script&gt;标签是什么?
  • 你在哪里调用 payment_field() 以及调用了多少次?

标签: jquery wordpress woocommerce


【解决方案1】:

将您的提交事件移到任何函数或循环之外

jQuery("form.woocommerce-checkout").on('submit', function (e) {
//submitinfo to the server
 }
function payment_field(){
//rest of the code...

【讨论】:

  • 如果我将它分开,它将无法工作,因为我正在将提交的账单信息发送到他们的服务器
  • 我不明白你为什么不能这样做?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-16
  • 2016-03-14
  • 2017-12-23
  • 2019-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多