On the serverside, a request to "whatever.com/export/foo'" generates a file and then returns an HTTP redirect to that file. Without Ajax, the browser follows the redirect and gives me an "open/save" dialog as you'd expect.

With Ajax, I was expecting the success function above to output an object with status=302 and a redirect URL which I could push to location.href. Actually what I get in the console is "Object tId=8 status=200 statusText=OK". Firebug also shows me that the browser does honor the redirect and actually downloads the file, but I get no "open/save" dialog.

What's the correct way of dealing with this situation? I really want my serverside code to remain the same for both Ajax and non-Ajax operation.

Thanks for your reply. From your input, my guess is that the 200 response I'm seeing in the success function is generated *after* the redirect (i.e. the browser is following the 302, downloading the file successfully and reporting a 200 status). This also explains why FireBug crashes when I try to examine the response object - the file it's downloading is ~5MB.

So, I guess that changes my question slightly: is there any way to intercept the 302 redirect and act on it? Obviously I don't want to be downloading the file via Ajax; instead, I should capture the redirect URL and push it to location.href to download the file normally.

But...are you sure that the browser is catching the 302-redirect and then 'redirecting' to the new location? Have you seen the 302 code?... maybe you are receiving directly the file without a redirect...