Is XMLHttpRequest allowed on glitch?

I am using XMLHttpRequest’s in my webpage and I was wondering if this was actually possible due to the fact that my webpage works on a local host but using glitch, it throws a error.

Error:
Access to XMLHttpRequest at ‘discord webhook here’ from origin ‘https://agrwebhooks.glitch.me’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Yes, they are allowed but they can be tricky to use. You can always use “cors-anywhere” to fix this. Add https://cors-anywhere.herokuapp.com/ in front of your URLs.

I am a little confused on that, can we talk on discord?
If you have discord, friend me AGR#0002
If not just let me know

To help others, we should talk here. What do you need help with?

I do not understand how the site works

Its more or less a proxy to fix issues with CORS.

Okay, at what part would I add implantations to my code? request.open? request.setRequestHeader? request.send?

where would i add this proxy?

Add it in front of the original url.

If my original url is https://agrwebhooks.glitch.me/, where would i put the proxy?

Is it a static project or a node server? If it’s a node/express server you can directly disable the CORS policy. Otherwise, you will have to use some sort of proxy like what @RiversideRocks suggested when making the request. Best to give it a Google.

It’s like this:
https://cors-anywhere.herokuapp.com/urlhere

So, with your url, you’ll just put it like this:
https://cors-anywhere.herokuapp.com/https://agrwebhooks.glitch.me/

Then, you just use XMLHttpRequest / fetch normally!

Here is sample code. This should work

var proxyUrl = "https://cors-anywhere.herokuapp.com/"
var link = "https://agrwebhooks.glitch.me/"
fetch(proxyUrl + link)

You can also read more about in the link itself: https://cors-anywhere.herokuapp.com/

4 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.