I have a website where I want to provide an option for users, if they click on a table\'s rows, they get regirected to another page (based on the contect of the table row).
No.
A redirect tells the client that the resource they just requested can be found elsewhere.
The page that was previously loaded which contains that JavaScript is not the resource that the Ajax request is asking for. Something will be returned though—it should get the resource that you redirected to (which will be available in xhr.responseText
(assuming the same origin policy doesn't interfere and that you get a 200 OK
response at the place you are redirecting to)
If you intend to always redirect, then don't use Ajax.
If you intend to sometimes redirect, then you'll need to put the URL in the body of the response, parse it with JavaScript and then assign it to location
.