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

326
Vistas
Using AJAX Post and Node.js Express

I am trying to send data from my html for node.js Express using a post method.

Using this code on my html file:

function readfile() {
var data = {};
data.path = '/home/test/pgadmin.txt';
data.ext = '.txt';
console.log(data);
  $.ajax({
    url: '/read_file',
    type: 'POST',
    contentType: 'application/json',
    data: JSON.stringify(data),
    success: function(data) {
      console.log(data);
    }
  });
}

And this is the code that I'm using on server side.

var express = require('express')
var path = require('path')
var app = express()

app.post('/read_file', function(req, res) {
   console.log(req.data.path) //?
   console.log(req.data.ext) //?
   //I dont know how to get the values of my data: here

})

Is there some way to get those data values without using bodyparser?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I'm not sure why you don't want to use bodyParser, but this could be done like:

var express = require('express');
var path = require('path');
var app = express();
var bodyParser = require('body-parser');

app.use(bodyParser.json());

app.post('/read_file', function(req, res) {
   console.log(req.body);
});

Of course you have to install bodyParser npm module as Brian pointed out.

See How do I consume the JSON POST data in an Express application

over 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