![](/img/trans.png)
[英]Access to XMLHttpRequest from origin 'null' has been blocked by CORS Policy?
[英]Getting error origin 'null' has been blocked by CORS policy?
我正在使用以下代碼調用 AWS API 網關。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
var finalJson = {
"entityType": "abc",
"entityId": "123"
};
$.ajax({
type : "POST",
contentType : "application/json",
xApiKey : "api-key"
url : "api-gateway-url",
data : JSON.stringify(finalJson),
dataType : 'json',
timeout : 100000,
success : function(data){
alert('Congrats! You got the response');
console.log(data);
},
error : function(data){
alert('Error');
console.log(data);
}
});
});
});
</script>
</head>
<body>
<h2>API Gateway call</h2>
<button type="button" id="btn">Request data</button>
<p id="demo"></p>
</body>
</html>
API Gateway 有一個 POST 方法,它與 Lambda 函數鏈接。 我已經在 API gatewaye 中啟用了 CORS。 點擊Request data按鈕后,顯示如下錯誤。
Access to XMLHttpRequest at 'API Gateway URL' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
請幫忙,謝謝:)
我認為這個問題與此相關,而不是因為 API 網關。 如果您使用*
配置了 CORS 配置,您應該可以直接從前端調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.