【问题标题】:why Ajax not properly work on live server?为什么 Ajax 不能在实时服务器上正常工作?
【发布时间】:2021-12-24 07:04:41
【问题描述】:
function couponCal() {
  $.ajax({
    type:"GET",
    dataType:'json',
    url:"{{ url('coupon/calculation') }}",
    success: function (data) {
      var d = $('.cart-ship-charge span').empty();

      if (data.total) {
        $('#couponCal').html(
          `<tr>
            <th>
              <div class="cart-sub-total">
                Subtotal<span class="inner-left-md">$ ${data.subtotal}</span>
              </div>
              <div class="cart-grand-total">
                Grand Total<span class="inner-left-md">$ ${data.total}</span>
              </div>
              <div class="cart-ship-charge">
                Ship Charge<span class="inner-left-md">$ ${data.ship_charge}</span>
              </div>
            </th>
          </tr>`
        )
      } else {
        $('#couponCal').html(
          `<tr>
            <th>
              <div class="cart-sub-total">
                Subtotal<span class="inner-left-md">$ ${data.subtotal}</span>
              </div>
              <div class="cart-sub-total">
                Coupon Name<span class="inner-left-md">$ ${data.coupon_name}</span>
                <button type="submit" onclick="couponRemove()"><i class="fa fa-times" aria-hidden="true"></i></button>
              </div>
              <div class="cart-sub-total">
                Discount Amount<span class="inner-left-md">$ ${data.discount_amount}</span>
              </div>
              </div>
              <div class="cart-ship-charge">
                Ship Charge<span class="inner-left-md">$ ${data.ship_charge}</span>
              </div>
              <div class="cart-grand-total">
                Grand Total<span class="inner-left-md">$ ${data.Grand_total}</span>
              </div>
            </th>
          </tr>`
        )
      }
    }
  });
}

couponCal();

$(document).on('click', '#ship_btn', function (e) {
  e.preventDefault();
  couponCal();
  $('#proceedCheck').show();
});

couponCal() 无法正常工作。我该怎么办?

【问题讨论】:

  • “没有正常工作”不是正确的问题描述。
  • 在 couponCal 函数中不显示数据,其中显示运费、小计、总金额等数据而无需重新加载页面
  • 添加一个错误回调并检查它是否给你任何错误。
  • 我们无法为您调试服务器错误。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: jquery ajax laravel


【解决方案1】:

我在制作过程中遇到了同样的问题。

在我的情况下,问题是 https,如果没有重定向,我的服务器只接受 https 请求。所以我更新了我的 appserviceprovider

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\URL;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Paginator::useBootstrap();
        URL::forceScheme('https');
    }
}

【讨论】:

    猜你喜欢
    • 2019-02-26
    • 1970-01-01
    • 2011-11-11
    • 2012-12-26
    • 2014-06-23
    • 1970-01-01
    • 2013-04-18
    • 2017-05-02
    • 1970-01-01
    相关资源
    最近更新 更多