Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
axios API - wait for response

I'am sending data to server with axios library

the query is working, but i'am not able to wait the answer of axios

import axios from '../helper/axiosAPI'

 /** data send to axios */
 let formData = new FormData();
 formData.append('file',this.file);

 /**Axios query */
 try{
    axios.post(formData)  
    .then(res=> console.log('result : ' + res)) // no data recieve              
  }
  catch(err){
    console.log(err)
  }

here my post request (axiosAPI file):

axios = require('axios').default;
const uri = process.env.VUE_APP_URI;
const endPoint = 'professional/upload'

 exports.post = async (formData) =>{
 axios({
    method:'post',
    url:uri + endPoint,
    data:formData,
    headers:{
        "Content-Type": "Content-Type: multipart/form-data"
    }
})
.then(response => {   
    console.log('axios : ' + response) // response is recieved    
    return response.data })
.catch(err => console.log(`Erreur AXIOS API : + ${err}`));

}

my Axios query work well and data is post to server. But i am not succed to wait the reponse from the server.

console.log('result : ' + res)=> (res is undefined -> not waiting for axios response)

console.log('axios : ' + response) =>(response is recieve from server)

It will be very nice if you help me to find a solution to wait axios result

thanks a lot

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use the await with axios:

Like this:

try
{
    let res = await axios.post(formData);
    console.log('result : ' + res); // no data received
}
catch(err)
{
    console.log(err);
}

and this:

const axios = require('axios').default;
const uri = process.env.VUE_APP_URI;
const endPoint = 'professional/upload';

exports.post = async (formData) =>{
    try
    {
        let response = await axios(
            {
                method: 'post',
                url: uri + endPoint,
                data: formData,
                headers:
                {
                    "Content-Type": "Content-Type: multipart/form-data"
                }
            }
        );

        console.log('axios : ' + response); // response is received    
        return response.data;
    }
    catch (err) 
    {
        console.log(err);
    }
}

See also:

https://stackoverflow.com/a/49661388/194717

https://www.npmjs.com/package/axios

about 4 years ago · Juan Pablo Isaza Denunciar

0

Since your handle is async so you need to put await before axios calling.

exports.post = async (formData) =>{
 return await axios({
    method:'post',
    url:uri + endPoint,
    data:formData,
    headers:{
        "Content-Type": "Content-Type: multipart/form-data"
    }
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda