1

I need to send an xmlhttprequest to a page that returns 302 and redirects and not to the redirected page, I saw this : Problems with xmlhttprequest status 302

but this solution only works in Firefox, i need something that will work for IE and Chrome.

Thanks

Community
  • 1
  • 1
Matan L
  • 997
  • 3
  • 14
  • 35
  • Not sure this is possible, sadly - I think the spec for `XMLHttpRequest`s says they should follow redirects. – cloudfeet Mar 18 '13 at 10:37
  • Will this be running on clients with Flash? It would be a bit of a hack, but you could replace XMLHttpRequest with something that called through to Flash to do the actual request, giving you a bit more control. – cloudfeet Mar 18 '13 at 10:39

1 Answers1

0

This isn't possible to do client-side with JS. XMLHttpRequests follow redirects silently.

Would it work to use the server as a proxy? So you would make a request to "/utils/inspectRedirect?url=...", and it would return you something like:

{
    "originalUri": ...,
    "redirectUri": ...,
    "httpCode": 302
}

If you don't need the full data, just the redirect URI, then this shouldn't place any strain on the server (it can just make a HEAD request).

cloudfeet
  • 12,156
  • 1
  • 56
  • 57
  • i just need the url but i have no access to the server and it could be different servers... i just need to know which page is sending the redirect... you can see it with fiddler so the client knows about it, why cant i get this information with js ? – Matan L Mar 19 '13 at 08:46
  • Because of the defined behaviour for XMLHttpRequests. The closest you get is mention of a possible *future* "property to disable following redirects" in the [existing spec](http://www.w3.org/TR/2008/WD-XMLHttpRequest-20080415/#notcovered). If you need to track redirects, then a pure JS client-side solution using XMLHttpRequest is not possible. – cloudfeet Mar 21 '13 at 16:24