[英]The 'Access-Control-Allow-Origin' header contains multiple values (Plesk on Windows)
I have the following code in JS:我在 JS 中有以下代码:
// Function to feed the API
function FeedAPI() {
// Define the API endpoint URL
var apiUrl = "https://ifthenpay.com/api/gateway/paybylink/XXX-XXXX";
// Define the JSON API body
var apiData = {
"id": "1234",
"amount": ValueSelected(),
"description": $('#name').val(),
"lang": "en",
"expiredate": "",
"accounts": "",
"selected_method": PaymentSelected()
};
console.log("API data: ", apiData);
// Use jQuery's $.ajax() function to make the request
$.ajax({
type: "POST",
url: apiUrl,
data: JSON.stringify(apiData),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
console.log("API response: ", response);
},
error: function(xhr, status, error) {
console.error("Error: ", error);
}
});
}
But get this error: Access to XMLHttpRequest at 'https://ifthenpay.com/api/gateway/paybylink/XXX-XXXX' from origin 'https://example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.
但是出现此错误: Access to XMLHttpRequest at 'https://ifthenpay.com/api/gateway/paybylink/XXX-XXXX' from origin 'https://example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.
I'm using Plesk on Windows and already tried to set my web.config
file to the following:我在 Windows 上使用 Plesk,并且已经尝试将我的web.config
文件设置为以下内容:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
At this point, I tried everything... Can someone help??在这一点上,我尝试了一切......有人可以帮忙吗?
So, I fixed my issue by just changinging the method of the API Integration to "GET".因此,我通过将 API 集成的方法更改为“GET”来解决我的问题。
Here is the code:这是代码:
function FeedAPI() {
// Define the API endpoint URL
var apiUrl = "https://ifthenpay.com/api/gateway/paybylink/get";
// Define the query parameters
var apiParams = {
"gatewaykey": "XXX-XXXX",
"id": "1234",
"amount": ValueSelected(),
"description": $('#name').val(),
"lang": "en",
"expiredate": "",
"accounts": "XXX|YYY;MBWAY|XXX-XXXXX",
"selected_method": PaymentSelected()
};
console.log("API params: ", apiParams);
// Use jQuery's $.ajax() function to make the request
$.ajax({
type: "GET",
url: apiUrl,
data: apiParams,
success: function(response) {
console.log("API response: ", response);
window.open(response.link, "_blank");
},
error: function(xhr, status, error) {
console.error("Error: ", error);
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.