Skip to main content
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad
Relanzada por el usuario Comunidad

Estoy haciendo practicasprácticas en React usando apiAPI de https://jsonplaceholder.typicode.com/users y todo funciona bien en local server pero cuando mando a subirla en githubGithub con gh-pagesgh-pages tengo un error en consola:

Access to fetch at 'https://jsonplaceholder.typicode.com/users' from origin 'https://fc0l.github.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Access to fetch at 'https://jsonplaceholder.typicode.com/users' from origin 'https://fc0l.github.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

el codigo que tengo es:

componentDidMount() {
    fetch('https://jsonplaceholder.typicode.com/users')
    .then(response=>response => response.json())
    .then(users=>users => this.setState({ user: users }));
}

Estoy haciendo practicas en React usando api de https://jsonplaceholder.typicode.com/users y todo funciona bien en local server pero cuando mando a subirla en github con gh-pages tengo un error en consola:

Access to fetch at 'https://jsonplaceholder.typicode.com/users' from origin 'https://fc0l.github.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

el codigo que tengo es:

componentDidMount(){
    fetch('https://jsonplaceholder.typicode.com/users')
    .then(response=> response.json())
    .then(users=> this.setState({ user:users }));
}

Estoy haciendo prácticas en React usando API de https://jsonplaceholder.typicode.com/users y todo funciona bien en local server pero cuando mando a subirla en Github con gh-pages tengo un error en consola:

Access to fetch at 'https://jsonplaceholder.typicode.com/users' from origin 'https://fc0l.github.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

el codigo que tengo es:

componentDidMount() {
    fetch('https://jsonplaceholder.typicode.com/users')
    .then(response => response.json())
    .then(users => this.setState({ user: users }));
}
Origen Enlace
fc0l
  • 21
  • 1
  • 4

Problema con fetch y CORS en React

Estoy haciendo practicas en React usando api de https://jsonplaceholder.typicode.com/users y todo funciona bien en local server pero cuando mando a subirla en github con gh-pages tengo un error en consola:

Access to fetch at 'https://jsonplaceholder.typicode.com/users' from origin 'https://fc0l.github.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

el codigo que tengo es:

componentDidMount(){
    fetch('https://jsonplaceholder.typicode.com/users')
    .then(response=> response.json())
    .then(users=> this.setState({ user:users }));
}