Camilo Morales Camilo Morales - 8 days ago 6
Node.js Question

How finish res without change page?

With

res.end()
or
res.send()
the result is a blank page, so how to finish without changing the page? My code is the following:

router.post('/subirArchivo/:idProducto', function (req, res){
var idProducto = req.params.idProducto;
var form = new formidable.IncomingForm();
var dir = '../../../../uploads/'+idProducto+'/';
form.parse(req);

form.on('fileBegin', function (name, file){

checkDirectorySync(path.join(__dirname, dir));
file.path = path.join(__dirname,dir, file.name);
});

form.on('file', function (name, file){
console.log('Uploaded ' + file.name);
});

res.end;});

Answer

This is a client-side issue, not a server issue because it is the client that determines how this works.

If you let the browser submit a form on its own (normal form post submission), then it will be expecting a response back from the POST that it will show in the browser. You cannot change that if it is an automatic form submission.

If you use an Ajax call to post the data to the server and you prevent the default form post, then the response comes back to your Javascript and you can do anything you want with the returned response (including nothing). The page contents will not change on their own.

Comments