I have been working on my Javascript code since last night however, I can't seem to make it work, It is supposed to pull the visits from my API which is connected to my Lambda function and DynamoDB. It is giving me the following error:
(index):1 Access to fetch at 'api link here ' from origin 'origin here' 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.
I fixed this problem by installing a CORS remover on Google Chrome however it then gives me this error:
VM37:4 Visitor Count:undefined
VM37:7 Uncaught (in promise) TypeError: Cannot set property 'innerHTML' of null
at <anonymous>:7:54
Does anyone know how to fix this error and make my JS pull information from my API link, I would appreciate it. Code is below.
fetch('api link here')
.then(function(sitevisits)
{
console.log("Visitor Count:" +
sitevisits.visits);
document.querySelector("#Visitors-text").innerHTML = "Total Visitors"+
sitevisits.visits;
});