1

I have the XMLHttpRequest (Native JS). This request is going through the mod rewrite (in .htaccess) and what I need to know - it's the "final" url (url after mod rewrite). I can see it in the "General" section in headers in Chrome console for this request, but I can't find the answer how I can get this value in JS.

Solution is going to work in any of modern browsers (IE10+).

halfer
  • 19,824
  • 17
  • 99
  • 186
WeekendMan
  • 561
  • 1
  • 10
  • 25
  • where is code?? – ricky Jan 16 '17 at 15:05
  • It is _specified_ that redirects have to be followed transparently when using XMLHttpRequest; transparently meaning that whatever happens in that regard is kept from the script on purpose. I don’t know if there is any (cross-browser) way to get that information; if you can modify the server-side part, then I would perhaps try and send that value as an additional header with the final response (`X-Final-URL: …` or sth. like that), so that you can access it using getResponseHeader. – CBroe Jan 16 '17 at 15:06
  • CBroe, yes, thanks, I thought about it (server-side part option), but it's not a good option for some reasons. But if there is no way to do it via JS... – WeekendMan Jan 16 '17 at 15:11
  • ricky, code is typical var xnr = new XMLHttpRequest(); xnr.open('GET', '/zzz/zzz', true); xnr.send(); xnr.onreadystatechange = function(){...}; – WeekendMan Jan 16 '17 at 15:12
  • http://stackoverflow.com/questions/22622858/detecting-a-301-redirect-using-client-side-code-only – Panama Prophet Jan 16 '17 at 15:26
  • Totally not my case. – WeekendMan Jan 16 '17 at 15:39

0 Answers0