簡體   English   中英

如何修復“狀態”:403,“錯誤”:“禁止”,“消息”:“訪問被拒絕”? 當我使用Ajax調用API時

[英]How to fix “status”:403,“error”:“Forbidden”,“message”:“Access Denied”? when I call API using Ajax

當我將API調用POST請求時,我收到錯誤403並且“已被CORS策略阻止。

這是我的Ajax代碼:

$.ajax({
    type: "POST",
    enctype: 'multipart/form-data',
    url: $('meta[name="server-config"]').attr('content') + "/file/upload/?user_id=" + response.user_id,
    data: data,
    headers: {
        'Authorization': `Bearer ${$('meta[name=auth-key]').attr('content')}`
    },
    processData: false,
    contentType: false,
    cache: false,
    timeout: 3000,
    success: function (data) {
        console.log(data)
        // location.reload();
    },
    error: function (e) {
        console.log("ERROR : ", e);
    }
});

在post方法文件中添加以下標題並嘗試

header('Access-Control-Allow-Origin: *');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM