Answer the question
In order to leave comments, you need to log in
How to properly transfer files from server to express via jquery(ajax) get requests?
I make a get request to the server and return the pdf file. At the same time, something incomprehensible comes to the browser, the download does not occur.
I heard somewhere that ajax requests do not return a file and you need to download it from a link.
Below is the request code and handler on the server.
$.get('/backend/exportVisitors', {eve: eve}, (data) => {
console.log('data', data);
});
app.get("/backend/exportVisitors", urlencodedParser, function (request, res) { //export visitors
if(!request.body) {
res.send('Ошибка!');
return res.sendStatus(400);
}
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'attachment; filename=Visitors.pdf');
// file.pipe(res);
res.download('register/temp/registrationSertificate.pdf', 'Visitors.pdf');
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question