Pure JavaScript code for HTTP Basic Authentication?

system PAUSE picture system PAUSE · Jan 29, 2009 · Viewed 91k times · Source

Where can I find reference code that implements a HTTP Basic Authentication client in pure JavaScript, suitable for AJAX?

Extra points for code, or pointers to code, that can be used independent of JS toolkits like YUI. No points for Java, Flash/Flex, PHP frameworks, etc.

Answer

Alnitak picture Alnitak · Jan 29, 2009

The five-parameter version of the XMLHttpRequest.open method allows you to specify the username and password. (WHATWG spec)

xhr.open(method, url, async, username, password)