XMLHttpRequest and redirects
07.03.07 19:27
Hit a major bummer while updating the Punk widget
today. Essentially, the onreadystatechange
handler will miss the redirect/Location: (302) header
being sent. IMDb uses 302 when there's only one
search result and catching that was a really nice
shortcut instead of having to parse the page to find
out what has happened. The widget used curl
before with which it's super-easy to notice these
things, but for some other reasons, I had already
re-written everything to use XMLHttpRequest.
Solutions? None so far, at least not for JavaScript. I think I've tried every possible way and place to stick getAllResponseHeaders(), including combining it with setTimeout(), but no cigar. The problem is, this behaviour is in the spec, so there's really no-one to blame. (?)
It really seems that, in my case, the "easiest" thing to do is just taking a peak at the page title. With IMDb it's easy - it's "IMDb Title Search" whenever there's more than 1 result.
Solutions? None so far, at least not for JavaScript. I think I've tried every possible way and place to stick getAllResponseHeaders(), including combining it with setTimeout(), but no cigar. The problem is, this behaviour is in the spec, so there's really no-one to blame. (?)
It really seems that, in my case, the "easiest" thing to do is just taking a peak at the page title. With IMDb it's easy - it's "IMDb Title Search" whenever there's more than 1 result.
|