簡體   English   中英

從 Jquery 調用 AWS API 時出現 CORS 錯誤

[英]Getting CORS error when calling AWS API from Jquery

從 Jquery 調用 AWS API 時出現 CORS 錯誤。

CORS 已在 API 端啟用,我可以使用 react > Axios 調用,但我們必須為此應用程序使用 ZA565B176ECE81D9AFB1ZA568。

使用此代碼:

 $.ajax({
      type: 'POST',
      url: "https://awsapiurlhere",
      crossDomain: true,
      async:true,
      data: {
      aaa: "444",
      bbb: "aaa",
      ccc: "ccc"
      },
      dataType: 'JSON',
      cors: true ,
      contentType:'application/json',
      headers: {
          "Access-Control-Allow-Origin":"*",
      },
      success: function(response, status, xhr) {
        if (response) {
          console.log("The username you typed has been used!", status);
        } else {
           console.log("No responce" , status);
        }
      },
      error: function(xhr, status, error) {
       console.log("Something went wrong!", status );
      }
    });

得到

Access to XMLHttpRequest at ' https://url ' from origin ' https://cdpn.io ' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers在預檢響應中。

您正在發送 Access-Control-Allow-Origin 作為請求的一部分。 根據錯誤消息,CORS 策略不允許請求 header。 您在請求中不需要此 header,因為它是響應 header。 從請求中刪除此 header 將解決此問題。

暫無
暫無

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

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