Pure JavaScript code for basic HTTP authentication?

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

Extra points for code or pointers to code that you can use regardless of your JS toolkit, such as YUI. No dots for Java, Flash / Flex, PHP frameworks, etc.

+54
javascript ajax basic-authentication
Jan 29 '09 at 14:59
source share
2 answers

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

 xhr.open(method, url, async, username, password) 
+57
Jan 29 '09 at 15:18
source

There is a good article / tutorial written by Paul James . I used it a while ago and it worked for me.

HTTP authentication using HTML forms

[...] XMLHTTPRequest, it can provide for HTTP HTTP headers. Instead of adjusting the URL of the form submits, we can use XMLHTTPRequest to make a request before the form sends a delivery of the entered username and password.

This will create a browser with HTTP authentication data so it will also send them with our actual request to submit the form.

+23
Jan 29 '09 at 15:10
source



All Articles