This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
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: 61451
    
  67

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Browser Redirection and Ajax