This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Browser Redirection and Ajax" Watch "Browser Redirection and Ajax" New topic

Browser Redirection and Ajax

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426

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

Joined: Jan 10, 2002
Posts: 63874

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

[Asking smart questions] [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

Joined: Sep 29, 2008
Posts: 12617

Check if its an XHR request before sending back the response code?
I agree. Here's the link:
subject: Browser Redirection and Ajax
It's not a secret anymore!