Pregunta

I'm currently developing a Javascript file that needs to send data to a remote server via websockets and ajax POSTs. The code seems to run well, I can see the server being hit and the several browsers I've tested it in seem to work well. The problem is that in Chrome I always get a message:

XMLHttpRequest cannot load http://api.test.com/oauth/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://useclark.com' is therefore not allowed access.

Is this a known bug in Chrome?

This is the request

$("#tokenbutton").click(function(){
                    $.ajax({
                       type: "POST",
                       contentType: "text/plain",
                       url: 'http://127.0.0.1:5000/oauth/token',
                       data: "grant_type=client_credentials&client_id=243257&client_secret=520e38c290995b78669acfd67391a8f6",
                       xhrFields: {
                          withCredentials: true
                       }
                    });
                });
¿Fue útil?

Solución

On your server, add the header 'Access-Control-Allow-Origin' with value '*' (or with the sites that you think should be allowed).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top