Answer the question
In order to leave comments, you need to log in
Why is req.xhr always false?
There is a test SPA site, the content is rendered by axios. Everything works fine, and when you would like to redirect to the main page during a normal page refresh, if not an hxr request, the problem is that req.xhr is always false
app.get('/test', function (req, res) {
// получаю с БД данные
//....
// только так пока что добился редиректа если не xhr
if (res.type('xhr').req.headers.accept === 'application/json, text/plain, */*') {
res.set('X-Requested-With', 'XMLHttpRequest')
res.render('test', {
title: 'Test',
test: result, // в шаблон pug данные из бд
})
console.log(req.xhr) // false
} else {
console.log(req.xhr)
res.redirect('/')
}
});
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