M
M
Michael2016-09-17 22:15:11
Node.js
Michael, 2016-09-17 22:15:11

Why can't I redirect the client?

Hello. On the client, I create the following XMLHttpRequest:

const xhr = new XMLHttpRequest();
xhr.open('post', '/path', true);
xhr.setRequestHeader('x-redirect', 'true');
xhr.send();

I accept on the server via express:
app.post('/path', (req, res) => {
  res.redirect('/exit');
});

But nothing happens. In this case, the request itself is normally sent, the headers are recognized by the server

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2016-09-17
@mak_ufo

Through AJAX, as far as I know, you cannot redirect the client, but if you send a request, and from the request get the page and replace the content, in addition, you can use the History API to change the URL.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question