【问题标题】:403 error on Ajax Post Laravel shared hostingAjax Post Laravel 共享主机上的 403 错误
【发布时间】:2018-01-13 08:42:17
【问题描述】:

网站在其他主机上完全正常。这也是共享的。但是在发出 Ajax 发布请求时不适用于当前主机。服务器(不是应用程序)以 403 响应。

我现在该怎么办?我用邮递员,它工作正常。 url也没有问题。

更新: ajax请求代码:

$.ajax({
    type: "POST",
    url: window.location.href.split('?')[0],
    data: data,
    success: function(data){
        window.location = data.redirect_to;
    },
    error: function(data){
    },
    dataType: 'json'
});

【问题讨论】:

  • “我现在该怎么办?”发布带有问题的可疑代码?

标签: ajax laravel post hosting shared


【解决方案1】:

问题是标题中“未设置”内容类型。 我把代码改成:

$.ajax({
    type: "POST",
    url: window.location.href.split('?')[0],
    data: JSON.stringify(data),
    success: function(data){
        window.location = data.redirect_to;
    },
    error: function(data){
    },
    dataType: 'json',
    headers: {
        'Content-Type':'application/json'
    }
});

它奏效了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多