javascript - How to handle CORS policy: No 'Access-Control-Allow-Origin' problem
问题描述
for a white i am working an api problem but always face this problem and cant find any solution. Here is my ajax request
$(document).ready(function() {
var url = 'https://www.xeno-canto.org/api/2/recordings?query=bearded+bellbird';
$.ajax({
url: url,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
type: "GET",
dataType: "json",
data: {},
success: function(result) {
console.log(result);
},
error: function() {
console.log("error");
}
});
});
but in chrome console this result show up
Access to XMLHttpRequest at 'https://www.xeno-canto.org/api/2/recordings?query=Greater+Scaup' from origin 'https://www.birdpx.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Do you have any solition?
解决方案
解决此问题的唯一方法是使用代理。代理可以检索浏览器外部的内容并将其传递给您的客户端。这是一个常见问题,有很多选择,例如:
推荐阅读
- r - 在两个只能递增一定次数的数字之间创建一个数组?
- c# - 如何使用 Xamarin 在 iOS 13.4.1 中完整保存 GPS 数据的照片?
- javascript - 标题在视差滚动期间切断顶部图像
- flutter - 如何使用 StreamProvider 检查 Firestore 快照流的 ConnectionState?
- sql - SQL选择不加载其中具有特定值的行
- swift - 在 Swift 5 中未执行 sceneDidDisconnect Delegate 中的代码
- python - python中的评估?
- javascript - 如何使用 EJS 将 Map 对象传递给我的脚本文件?
- java - 泛型类型上限为泛型本身
- html - 为什么我的字体真棒图标背景没有加载?