i'm trying to fetch an api, but i keep getting this error:
index.html:1 Fetch API cannot load https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1. The 'Access-Control-Allow-Origin' header has a value 'http://null' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Here's the js file including the function attached to the click event on a button:
var header = new Headers({
'Access-Control-Allow-Origin': '*',
'Content-Type': 'multipart/form-data'
});
function newQuotes(){
fetch('https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1', {mode: 'cors', header: header})
.then(function(response) {
return response.json();
})
.then(function(response) {
console.log(response)
})
.catch(function(err) {
console.log('Fetch Error', err);
});
}
UPDATE I solved the problem by installing this extension Is it te only possible way? Why some people do not have to install it?