Node.js - Problem redirecting routine post method

Hi everyone

I write here for who can help me, since I'm new to NodeJS, I'm trying to do something simple, but in the end it doesn't work for me.

I want from the frontend, to make a request to the backend, through the ajax post method. When executing it, from the frontend send a JSON object to the backend and then from the backend it must redirect to another page to the frontend (the latter is what I could not achieve)

Example of what I try

Frontend
var objAgente = {
"FIRSTNAME": "PEDRO",
"LASTNAME": "PEREZ",
"NRORUT": "123456789",
"NROAGENT": "3",
"HRCONNECT": "12:12:12"
};

$.ajax({
type: 'POST',
url: '/LoginAgente',
data: JSON.stringify({ "objectData": objAgente}),
success: function(data) {console.log('todo OK')},
contentType: "application/json",
dataType: 'json'
});

Backend
const express = require("express");
const router = express.Router();

router.use(express.json()) // for parsing application/json

router.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded

router.get('/', (req, res)=>{

res.render('loading.html', { title: 'Iniciando Sistema'});

});

router.get('/Inicio', (req,res)=>{

res.render('confInitial.html', { title: 'Inicio de Sistema'});

});

router.get('/Agente', (req,res)=>{

res.render('PanelAgente/Agente.html', { title: 'Equipo solo Agente'});

});

router.post('/LoginAgente', function (req, res) {
var newUser = req.body;
console.log(newUser);
res.redirect('/Agente');

});

module.exports = router;

When I execute the sending of the JSON object to the backend, the data arrives since I can print it by console, but the res.redirect is not fulfilled;

It does not return an error, but it does not redirect me to where I want.

Thank you very much to those who can give me an idea of ​​what happens

Hi @Rngelmiguel

This isn't a general node.js support forum - it's for Node-RED.

You may want to post your question to Stack Overflow where I'm sure there will be plenty of node.js developers who can help.

1 Like