Coding
1
Hey Community!
I was attempting to get data from this page:
https://discord-channel-bot.glitch.me/stats
It worked, but I got the following error:
'Access-Control-Allow-Origin' header is present on the requested resource.
I know this is a CORS error, but I don’t know how to allow it to get the JSON file on a different glitch project.
Thanks,
Codingpro
So you’re trying to get https://discord-channel-bot.glitch.me/stats from another Glitch project and getting that error?
This might help if discord-channel-bot uses express
Coding
3
I see. I’m currently using Jquery right now tho. Would this code go on the data side or the GET side? The data side has express.
Coding
4
Never Mind! It worked! I put it on the data side, and I don’t seem to get the error anymore!
Coding
5
FIXED
Solution:
Paste the following code before any other express code:
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
Oh great, yeah was just checking it and looked right!