File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Browser Redirection and Ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Browser Redirection and Ajax" Watch "Browser Redirection and Ajax" New topic
Author

Browser Redirection and Ajax

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi,

I am new to ajax and I am not sure of what I am observing but hopefully somebody could give me light on this.

I notice that when I return a 302 HTTP response from a call with Jquery $.ajax() or $.json(), the browser is handling the redirection itself and I cannot get the xhr.status of 302 but always 200.

Is what i notice correct and is there any workaroubd for this? I see on my firebug the 302 response code but it is handing me a status of 200 and not the 302.




Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Why would you be sending a redirect as a result of an Ajax request?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
well, i configured a servlet filter that intercepts all url request if there is session associated with it. If not, they are redirected to the login page. For non-xmlhttprequest, this works fine. But when I issue an ajax request, i cannot get hold of the 302 http response. The browser is handling it for me, and what i get is an xhr status of 200. Is my observation, correct?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Check if its an XHR request before sending back the response code?
 
 
subject: Browser Redirection and Ajax
 
Similar Threads
Session Timeout on Ajax Calls
redirection is going to infinite loop if url is not having the www domain
Issue in returning 302 response code instead of 200 response code
servlet to receive and forward HTTP status.
How to redirect but return code 200 ?