# CORS error with JS

**URL:** <https://forums.knack.com/t/cors-error-with-js/11561>\
**Category:** Ask the Community\
**Created:** [November 16, 2021, 10:57am UTC](https://forums.knack.com/t/cors-error-with-js/11561 "2021-11-16T10:57:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benton](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@Benton](https://forums.knack.com/u/Benton)\
**Post date:** [November 16, 2021, 10:57am UTC](https://forums.knack.com/t/cors-error-with-js/11561/1 "2021-11-16T10:57:20Z")

</div>

Sometimes I get this error when trying to fetch data from KNACK with JS. I tried a lot of fetch options etc. Sometimes it is ok sometimes I got CORS error. Is there any way to fix this?  
Thanks

> Access to fetch at ‘[https://s3-ap-southeast-2.amazonaws.com/ap-southeast-2-assets.knack.com/assets/616391ee2e9161001e613faa/616392568f236607184d4ba0/original/proposedretail.png](https://s3-ap-southeast-2.amazonaws.com/ap-southeast-2-assets.knack.com/assets/616391ee2e9161001e613faa/616392568f236607184d4ba0/original/proposedretail.png)’ from origin ‘[http://127.0.0.1:5500](http://127.0.0.1:5500)’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

here are my fetch options  
const knackURL = ‘[https://api.knackhq.com/v1/objects/](https://api.knackhq.com/v1/objects/)’  
const fetchOptions = {  
cache: “force-cache”,  
method: ‘GET’, // \*GET, POST, PUT, DELETE, etc.  
mode: ‘cors’, // no-cors, \*cors, same-origin  
credentials: ‘same-origin’, // include, _same-origin, omit  
headers: {  
‘Content-Type’: ‘application/json’,  
‘Access-Control-Allow-Origin’: '_',  
‘Access-Control-Allow-Methods’: ‘POST,PATCH,OPTIONS’,  
‘X-Knack-Application-Id’: knack\_id,  
‘X-Knack-REST-API-Key’: knack\_key  
}  
}

---

<div class="post-metadata">

**Author:** ![Arjun](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/arjun/32/4149_2.png) [@Arjun](https://forums.knack.com/u/Arjun)\
**Post date:** [November 16, 2021, 11:25am UTC](https://forums.knack.com/t/cors-error-with-js/11561/2 "2021-11-16T11:25:35Z")

</div>

Hey Benton. I see you’re trying to make this call from a localhost server. Sometimes a CORS block happens when you’re trying to access information from a server without an SSL certificate if the receiving server has https.

Can you try repeating the process using something like Ngrok to simulate a secure server?

---

<div class="post-metadata">

**Author:** ![Benton](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@Benton](https://forums.knack.com/u/Benton)\
**Post date:** [December 13, 2021, 7:16am UTC](https://forums.knack.com/t/cors-error-with-js/11561/3 "2021-12-13T07:16:27Z")

</div>

Hey Arjun, it happens on HTTPS too.

I periodically receive error messages on JavaScript console about CORS error. Sometimes it is fine, but every second or third load it does not work. We use https. Thanks

Access to fetch at ‘[https://api.knackhq.com/v1/objects/object\_3/fields](https://api.knackhq.com/v1/objects/object_3/fields)’ from origin ‘[https://releaseplan](https://releaseplan).\*’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.
