Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda