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

153
Vistas
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
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