【问题标题】:VUEJS TypeError: $.ajax(...).success is not a functionVUEJS TypeError: $.ajax(...).success 不是函数
【发布时间】:2020-05-01 20:16:54
【问题描述】:

我想将 Vuejs 与本地支付网关连接,

在 index.html 上添加插件

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js"></script>
<script src="https://staging.doku.com/doku-js/assets/js/payment.js?version=<?php echo time()?>"></script> <!-- To prevent js caching -->
<link href="https://staging.doku.com/doku-js/assets/css/doku.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet">

下面是我的方法

showPaymentPage() {
  post("payment/credit-card", {
    amount: this.amount+'.00',
    invoice: this.invoiceNumber,
    currency: 360
  })
    .then(res => {
      if (res.data) {
        console.log(res.data);
        // this.payment = res.data.message
        const data = new Object();
            data.req_merchant_code = res.data.data.mallid; //mall id or merchant id
            data.req_chain_merchant = 'NA'; //chain merchant id
            data.req_payment_channel = '15'; //payment channel
            data.req_transaction_id = res.data.data.invoice; //invoice no
            data.req_amount = res.data.data.amount;
            data.req_currency = res.data.data.currency; //360 for IDR
            data.req_words = res.data.words; //your merchant unique key
            data.req_session_id = new Date().getTime(); //your server timestamp
            data.req_form_type = 'full';
            data.req_customer_id = this.$store.getters.getUser.id;

            getForm(data);
      }
    })
    .catch(e => {
      console.log(e);
    });
},

但在控制台日志上得到响应,如下所示

TypeError: $.ajax(...).success is not a function
at getForm (payment.js?version=1579060503:1)
at app.js:35908

请帮帮我,

【问题讨论】:

  • 你在哪里定义 axios?
  • 嗨 @JinalSomaiya 在同一个 file.vue 上
  • 有问题的请添加。
  • 请包含完整的必要代码,例如$.ajaxgetForm 的位置
  • hi @KarmaBlackshaw $.ajax and getForm on this url

标签: ajax laravel vue.js


【解决方案1】:

你的代码是正确的,没有问题,但是随着 jQuery 的最近更新,.success() 方法不再被允许,所以下面的代码会发出错误。

$.ajax(url).success

对于较新版本的jquery,你可以这样做:

$.ajax(url, {
  success: () => {
    // Do something
  }
})

或者

$.ajax({
  type: "GET",
  url,
  success: function () { 
    // Do something
  }
})

或者,您可以像这样简单地使用链方法:

$.ajax(url).then(x => {
  // Do something
})

或者

$.ajax(url).done(x => {
  // Do something
})

【讨论】:

    【解决方案2】:

    没有函数ajax().success。 你可以使用这样的东西:

    $.ajax({
          url: "getvalue.php",  
          success: function(data) {
             return data; 
          }
       });
       

    【讨论】:

      【解决方案3】:

      在我看来,没有定义成功函数。请记住,jquery 不使用承诺,这意味着您不能这样做.then/.catch

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-18
        • 2020-02-09
        相关资源
        最近更新 更多