首页 > 解决方案 > 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?

标签: javascriptjqueryjsonajaxapi

解决方案


解决此问题的唯一方法是使用代理。代理可以检索浏览器外部的内容并将其传递给您的客户端。这是一个常见问题,有很多选择,例如:

https://github.com/Shivam010/bypass-cors


推荐阅读