On Mittwoch, 22. Oktober 2008, Mike Alsup wrote: > > I would like to use $.ajaxSetup to set up a global error handler that > > knows how to deal with HTTP 401 codes ("Authentication required"). I > > am enhancing a few tables with AJAX using jQuery but I made my backend > > send back an HTTP error code 401 to force authentication if the user's > > login session timed out. The idea was to redirect to the '/login' page > > then. > > Well, normally the server would redirect on a session timeout
Would the client react properly if the server sent a "Location:" header as a response to an XHR? I hadn't expected jQuery to deal with that and change the "location" to what's in the response header. > but if > you want/need to do it on the client then use the xhr object that is > passed as the first arg to your error handler: > > $.ajaxSetup({ > error: function(xhr, status, err) { > if (xhr.status == 401) > window.location.href = './login'; > } > }); Thanks, that's what I was looking for. I didn't find the XHR object documented. Perhaps this code snippet is worth getting added to the documentation. :) Kindly Christoph
signature.asc
Description: This is a digitally signed message part.