Adding handling of HTTP 401 status codes in Ajax requests. Fixes #504