Uncaught TypeError: Cannot read property ‘split’ of undefined (: line 56)
TypeError: Failed to fetch
I’ve tried following the example in Reference but am stumped. Thx for whatever insights you can provide!
function preload() {
// Get color palette from colormind.io API
let url = 'http://colormind.io/api/';
let postData = {'model':'default'}
httpPost(url, 'json', postData);
}
function draw() {
background(220);
//nothing here yet
}
And effectively there’s an error related to CORS :
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://colormind.io/api/. (Reason: CORS request did not succeed).
TypeError: NetworkError when attempting to fetch resource.
This is caused by the fact that the creators of colormind.io didn’t enabled CORS headers and allowed requests from all origins.
Since fetch is using the Cross-Origin Ressource Sharing policy, you can read more about it here :
I also tried the JavaScript example at the end of the api page and it still gives me a CORS error. Most of the time it’s really anoying specially with APIs but it’s meant to be a security layer.
So you can contact the API provider asking them to add the CORS headers.
You can also take a look at that nice article, specially the Solutions section :
Hi and thank you!
Ugh CORS. I should have guessed. I will email them and ask for CORS headers - good suggestion. Thanks a ton for digging into this for me.