0

Quiero hacer esta petición con axios. Me ayudan a traducirla.

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.apoyamostueconomia.com/api/auth/registro");

xhr.send();

Estoy utilizando losiguiente:

 import axios form 'axios';
    
axios.create({
   baseURL: 'https://api.apoyamostueconomia.com/api/',
   withCredentials: true
});

axios.post('auth/register').then(res=>console.log(res), err=>console.log(err.response));

Pero solo funciona en firefox. No se porque motivo no funciona en google chrome.

Saludos.

2
  • 1
    ¿Qué errores te genera en Google Chrome?
    – fredyfx
    el 10 mar. 2020 a las 22:37
  • que no encuentra la cabecera Access-Control-Allow-Origin. Me di cuenta que laravel si necesita dos headers en el index para que funcione en todas las rutas. el 10 mar. 2020 a las 23:15

1 respuesta 1

0

puedes probar si esto funciona.

Axios({
  method: 'POST',      
  withCredentials: true,
  url: 'https://api.apoyamostueconomia.com/api/auth/register'
}).then(response => {
  console.log(response.data)
}).catch(error => {
  console.error(error);
});
1
  • 1
    Por favor considera leer Cómo responder, los aportes que son solo código se consideran de baja calidad, editar y explicar tu código no solo ayuda a quien preguntó sino también a toda la comunidad
    – user128299
    el 10 mar. 2020 a las 22:24

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.