The code you show is correct. My wild guess is that you’re not doing a standard POST (e.g., redirects don’t work with an AJAX post).
The browser will ignore a redirect response to an AJAX POST. It’s up to you to redirect in script if you need to redirect when an AJAX call returns a redirect response.