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

271
Vistas
Using axios to make a post request - node js

I'm new to node.js and i'm trying to do a post request from server side using axios But i get no response data from the request.

If i do a post request from the client side using ajax it works fine and i was just wondering am i doing something wrong?

My server side post request:

var postData ={
  a: 'getMessages',
  max: 50,
  id: 5039
};

let postConfig = {
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  }
};

axios.post('https://url.com/ajax.php', postData, postConfig).then((response) => {
  console.log('response:', response.data);
}).catch((error) => {
  console.log('error:', error);
});

The way i was doing post request from client side:

This worked fine but when i try to do a post request from server side there is no response data.

$.post('https://url.com/ajax.php', {
  a: 'getMessages',
  max: 50,
  id: 5039
}, function(response) {
  let data = JSON.parse(response);

  console.log('data:', data);
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Client-side, it looks like you're using jQuery $.post(), which defaults to posting JSON when sending an object like this.

I suspect that the issue is that your content type is sent to be a form. If you simply get rid of postConfig entirely, it should send it as application/json, and should properly format the request body for what you want.

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