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

246
Views
Can't read data in node.js from a Ajax POST request

I need help with a very simple problem, but which for some reason I can't solve. I have a ajax post request that send data to a node.js server. From the server side, data seems to be received, but I am not able to retrieve the data fields.

Extract from the Client side:

function validateUser() 
{   
      $.ajax({
      type: "POST",
      url: "/authAjax",
      data: {
        username: "myusr",
        password: "mypsw"
      },
      success: function( result ) {alert("OK");},
      error: function( result ) {alert("ERR");}
    });
}

Extract from the Server side (node.js):

app.post('/authAjax', function(req, res)
{
    req.on('data', function (chunk) {
        console.log(req.body);      // not working
        console.log(req.username);  // not working
        console.log(req.data);      // not working
        res.send("200");            
    });
});

The res.send("200"); is executed, but I have no chance to get the passed username and password values. Could someone give any hint here?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

These were missing on the node.js side:

 app.use(express.json());

And the data is accessible with:

 req.body
over 4 years ago · Santiago Trujillo 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!