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

221
Vistas
async await axios post data with vue js, the data send is different between vue and postmant

i try to create data with vue js, but backend can not read the data and just send "undefined" to database, i try create data with postman, backend can read the data,

i see the data captured on backend, it turns out that there is a difference between the data sent by vue js end the data sent by postman

here is the data sent by postman

[Object: null prototype] { name: '6', email: '5', password: '3' }

and here is the data sent by vue js

[Object: null prototype] {
  '{"name":"2","email":"2","password":"2"}': ''
}

here is the script in vue js

<script>
  import axios from "axios";
  export default {
    name: 'AddUser',
    data(){
      return {
        model: {
          name: '',
          email: '',
          id_status: '',
          password: '',
        }
      };
    },
    methods: {
      async saveUser(){
        try{
          const response = await axios.post('http://localhost:8000/users',this.model);
          res.data.headers['Content-Type'];
          console.log(response);
        } catch (err){
          console.log(err);
        }
      }
    },
  };
</script>

and here is script in node js as backend

if(q.pathname == "/users" && req.method == "POST"){
        var body = '';
        req.on('data', function(data){
            body += data;
            if(body.length > 1e6)
                req.connection.destroy();
        });

        req.on('end', function(){
            var postData    = qs.parse(body);
            let name        = postData.name;
            let email       = postData.email;
            let id_status   = postData.id_status;
            let password    = postData.password;            
            let sql = `insert into users (name,email,id_status,password) values ('${name}','${email}','${id_status}','${password}')`
            console.log(postData)
            db.query(sql,(err, result) => {
                if (err) throw err;

                if(result.affectedRows == 1){
                    res.end(JSON.stringify({message: 'success'}));
                }else{
                    res.end(JSON.stringify({message: 'failed'}));
                }   
            });
        });
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

the problem is solved, i just change

var postData    = qs.parse(body);

to

var postData    = JSON.parse(body);

thanks for helping

about 4 years ago · Santiago Trujillo Denunciar
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