Ajax authentication demo

In response to my own StackOverflow question (http://stackoverflow.com/q/19022356/243557) I want to contribute a demo which covers a scenario which I believe is not covered by the otherwise good documentation. It shows a way to manually handle authentication with Ajax login requests.