-
24 Mar 2008 8:14 AM #1
Following HTTP Redirects (302)
Following HTTP Redirects (302)
Hi all,
I'm trying to figure out how to recognize when an HTTP redirect comes back from an Ajax request. Here is my submission code:
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.Code:Ext.Ajax.request({ url: base.url+'/export/foo', method:'GET', success:function(response) { console.log(response) }, failure:function(response) { debug.popup(response.responseText); //show the server response in a dialog } })
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.
Many thanks,
Matt.
-
24 Mar 2008 8:44 AM #2
If you have in the console a status=200, is because the response from the server had been a http-200.
A response with http-302 is a failure.
Ext.Ajax only call success callback on http status >=200 and <300.
-
24 Mar 2008 9:43 AM #3
Hi Halkon,
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.
Thanks,
Matt.
-
24 Mar 2008 10:06 AM #4
You can try the hendricd's extension ext-basex.js (http://extjs.com/forum/showthread.php?t=21681) where you can intercept http status codes and assign a function to them...
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...
-
24 Mar 2008 10:24 AM #5
Thanks Halkon,
I'll give ext-basex a whirl - looks like it'll do everything I need.
Yes, upon closer inspection the browser definitely sees the 302; the Net tab on FireBug shows this:
Thanks for the excellent responses. Hopefully this thread will explain the behavior of 300 responses for some other folks too.Code:23 (302) http://whatever.com/export/foo?_dc=1206382633661 whatever.com 0 b 47ms foo.zip whatever.com/media/generated/foo.zip whatever.com 4.76 MB
Matt.
-
24 Jun 2008 12:37 PM #6
I was tempted by this thread to look at using basex for trapping redirect. Unfortunately basex can't handle 302 as the browser preempts it. See posts in another thread http://extjs.com/forum/showthread.php?t=21681&page=11
Bottom line - redirects considered harmful with ExtJS and other AJAX frameworks.
-
5 Nov 2012 9:51 PM #7
runAllManagedModulesForAllRequests="true"
runAllManagedModulesForAllRequests="true"
I had the same problem the issue is the propety set with module section of the web.config
runAllManagedModulesForAllRequests="true"
remove this and it should work



Reply With Quote