0
votes

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?

1

1 Answers

0
votes

The only way around this is to use a proxy. The proxy can retrieve the content outside of a browser and deliver it to your client. This is a common problem and there are many options such as:

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