Handle ajax calls in admin when user session has ended

When a user is logged in to admin but the user session has ended, all ajax request loads the login screen which the jQuery ajax call can't handle in a good way, and this makes the spinner go on forever. This little code creates a meaningful error message that the ajax call can catch and display. You just have to add checks for json['error'] in your jQuery ajax calls and display if it exist.

The keyword here is $this->request->server['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' which identifies the request as an jQuery ajax request.