Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!