1
I have an application that requests a JSON via Xios. It follows the function
axios.get("http://localhost/teste.json")
.then((res) => {
this.setState({value: res.data.tgt.screenPosX})
}).catch((err) => {
console.log('Error')
})
But as the development server is running on 3000 I cannot access this json on apache server due to CORS policy
Requisição cross-origin bloqueada: A política de mesma origem (Same Origin Policy) impede a leitura do recurso remoto em http://localhost/teste.json. (Motivo: o cabeçalho CORS 'Access-Control-Allow-Origin' não está presente).
How can I solve this problem? How do I consume this JSON without going through CORS?
I don’t know much about backend but I need to solve the problem yesterday.
Thanks in advance!!
Are you requesting a server you developed ? if yes, you can change the application’s CORS to accept requests for any domain.
– RickPariz
I didn’t exactly develop it, but it’s local and I have access to it. How can I do this, I have to allow the server in localhost to accept requests?
– Luiz Henrique Esper
What language are you using in the Back-End? You have to set up Cors in your Back End!
– Marconi
The backend ta in php, I will try to work on this and give feedback to you
– Luiz Henrique Esper