var paint = document.getElementsByTagName("img");
document.addEventListener("DOMContentLoaded", () => {
let radomID = Math.floor(Math.random() * 45734 + 1);
let link = "//collectionapi.metmuseum.org/public/collection/v1/objects/" + radomID;
const options = {
method: "GET",
headers: {
"Content-Type": "application/json"
},
'Access-Control-Allow-Origin' : 'https://collectionapi.metmuseum.org/'
};
fetch(link, options)
.then((response) => {
if(response.ok) {
return response.json();
} else {
throw new Error(response.status);
}
})
.then((response) => {
console.log(response.constituentWikidata_URL);
})
.catch((error) => {
console.log(error);
});
});
Hello, I´m here doing a petition and I want to know what's the next step to fix this problem:
Access to fetch at 'http://collectionapi.metmuseum.org/public/collection/v1/objects/43823' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request. script.js:16
GET http://collectionapi.metmuseum.org/public/collection/v1/objects/43823 net::ERR_FAILED (anónimo) @ script.js:16 script.js:31
TypeError: Failed to fetch
Maybe I have now to learn any back end technology and make the petitions from there.
The API doesn't need APIKey.
Thank you.