How to Fix CORS policy: No 'Access-Control-Allow-Origin' Error

i am trying to scrap data from Website name Kijiji but it throws a CORS policy Error i tried using Access-Control-Allow-Origin: * but it didn’t work out. Here’s my code

$(document).ready(function () {
 var feeds = ["https://www.kijiji.ca/rss-srp-rideshare-carpool/barrie/rideshare/k0c5l1700006",
        "https://www.kijiji.ca/rss-srp-rideshare-carpool/belleville-area/rideshare/k0c5l1700129",
    ]

    feeds.forEach(feed => $.ajax( feed, {
        accepts: {
            xml: "application/rss+xml",
            Access-Control-Allow-Origin: *
        },
        dataType: "xml",
        success: function (data) {
           console.log(data);
        }
    })); 

There isn’t a good way around it, for allowing your service to access the data is something the other server needs to support. One solution is to use an intermediate server that bypasses CORS along with taking your actual request and returning the right data.

You can see that approach used here: Checking If A File Exists

:slight_smile:

Bro is there any alternative way

No. The whole reason CORS exists is to protect sites from having 3rd party/untrusted sources access to their content :see_no_evil:

I found one website which instruct to apply Header on your server in my case i am using Apache how to set header in that

https://enable-cors.org/server_apache.html

Give it a shot. My guess is that, unless the server you are requesting data from loosens their restrictions, you won’t be successful.