首页 > 解决方案 > Ajax 调用在 Firefox 和 safari 中失败,但在 chrome 中运行良好

问题描述

我正在尝试使用 ajax 调用执行一个操作,在 chrome 中一切正常,但是当我在 firefox 或 safari 浏览器中执行相同的操作时,它会抛出错误的请求。我可以在网络选项卡中看到对 url 进行了调用,但未提供任何状态,然后使用 laravel 错误“MethodNotAllowedHTTPException”回调引用页面。我也在添加我的代码。

function transactionAction(value, id, amount){  
//event.preventDefault();
document.getElementById("formSubmitButton").disabled = true;
var SITE_URL = "{{url('')}}" + ('/web/v1/dispute-refund');
var actionId = value;
var pId = id;
$.ajax({
type: 'POST',
    url:SITE_URL,
    headers: {
    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
    },
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data:{
        actionId:actionId,
        pId:pId,
        amount:amount,
        "_token": "{{ csrf_token() }}"
    },
    success: function (response){
        $('.refund').modal('hide');
        if(response.result.status == true){
        $('.error-divbox-master').html('<div class="alert alert-success alert-dismissible"><h4><i class="icon fa fa-check"></i>'+response.result.message+'</h4></div>').delay(10000).show().fadeOut('slow');
        document.getElementById("formSubmitButton").disabled = false;
        }else{
          $('.error-divbox-master').html('<div class="alert alert-danger alert-dismissible"><h4><i class="icon fa fa-check"></i>'+response.result.message+'</h4></div>').delay(10000).show().fadeOut('slow');
          document.getElementById("formSubmitButton").disabled = false;
    }
    setInterval(function(){location.reload();},3000);
    },
    error: function (response) {
        $('.refund').modal('hide');
        $('.error-divbox-master').html('<div class="alert alert-danger alert-dismissible"><h4><i class="icon fa fa-check"></i>'+response.result.message+'</h4></div>').delay(10000).show().fadeOut('slow');
        document.getElementById("formSubmitButton").disabled = false;
    }
});
}

标签: ajaxlaravelgoogle-chromefirefoxsafari

解决方案


尝试方法:“POST”而不是 类型:“POST”


推荐阅读