I am trying to use a jQuery AJAX request to determine if a link contains a valid image. My code is functional, but the image refuses to load due to a CORS blocking error message.
My “_headers” and “netlify.toml” files are both present and both have “Access-Control-Allow-Origin” set to “*”. I’m still confused as to why it still says my header is not present.
Noah without seeing the error I can’t tell but are you sure it’s not a case of https://foo.bar server not sending the CORS header? If you have control of https://foo.bar you can modify it to send the header otherwise i’m not sure there’s much you can do here.
I unfortunately do not have access to the URL path to do anything custom there. The error I’m seeing in my Chrome devtools is as follows:
Access to XMLHttpRequest at 'https://foo.bar' from origin 'https://noahgrice-betterdark.netlify.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This error is confusing to me because the header is present in my “_headers” and “netify.toml” files. When uploading the most recent deploy, it even says “2 header rules processed with no errors.”
@noahgrice I am super noob with Netifly but I believe the _headers file is to define headers you want your serverless functions to send when they get a request. It’s not going to have an effect on the foo.bar server and what headers it will send.
Is it the URL one might enter in the background image input? If so, it is nothing to do with Access-Control-Allow-Origin of your site, but that of the site the image is loaded from.
For example enter one of your portfolio images: https://www.noahgrice.com/img/portfolio/motion/exility.jpg and you’ll see it will load. Why? Because the headers for the image are allowing it
The fact that you have Access-Control-Allow-Origin: * on your site means any site can load any resource without issue, image, CSS, JS, etc. because you have explicitly permitted it. This is potentially not what you want.