I can't seem to authenticate by making a POST request via ajax! I always get an HTTP 400 error. What could be the issue?
That's Cross Site Scripting, dummy! You can't do that with vanilla JavaScript.
If you really need to use JavaScript, a client library is available.