0

I am getting this error on a JS script:

Access to XMLHttpRequest at 'https://services.3xsoftware.co.uk/Search/ByPostcode/' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Here's my code and I have set up the headers but still it is not working. Please let me know if I am doing anything wrong:

 axios.get('https://services.3xsoftware.co.uk/Search/ByPostcode/' + postcode,
    "",
    {
        headers: {
            'Access-Control-Allow-Origin': '*',
        },

        responseType: "json",
    }
)
  • 1
    This isn't my strong suit, but I believe you're supposed to set that `Access-Control-Allow-Origin` header from the API side. But this looks like it's your client side where the request is being made from. – jnotelddim Oct 15 '21 at 17:27
  • Does this answer your question? [XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header](https://stackoverflow.com/questions/35553500/xmlhttprequest-cannot-load-xxx-no-access-control-allow-origin-header) – 3limin4t0r Oct 15 '21 at 17:53

1 Answers1

1

This is a configuration issue on the server of your requested resource. It specifies which origins, so in this case, your vue instance, can access that server. If you have control over the server, you need to configure allowed origins. If you don't control the server, there isn't much that you can do.