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

157
Views
How to insert data to Mongodb with ajax $.post in the client side?

I am trying to insert data to Mongodb with the ajax $.post in the client side as the clident side using Cordova framework. But the data inserted to Mongo is empty, which is just has an ID. Below is the codes. Did I make any mistake? Could someone please help me figure it out? I am new to Mongo and ajax. Thanks!

codes in the client.js

 $("#myPost").on("click", function () {
            localData = localStorage.getItem('localData');

            $.post("http://localhost:3000/postData",{localData:localData}, function (data, status) {

                alert("Data received: " + data + "\nstatus: " + status);
            });
        });

codes in server.js

client.connect(err => {
  currCollection = client.db("mydb").collection("db");
  console.log ('Database connected!')

});

app.post('/postData', (req, res) => {
  
  currCollection.insertOne(req.body, function(err,result){
    if(err) {
      console.log(err);
    } else {
       console.log("Data inserted: "+result);
    }
  })
 
});

The post result in actually [object Object] but I tried many ways still couldn't resolve the problem.

about 4 years ago · Juan Pablo Isaza
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!