JS

HTTP AUTHENTICATION WITH AJAX HTPASSWD

CREATE USER & PASSWORD htpasswd -c "FOLDER\.htpasswd" USER

.HTACCESS

CREATE IN FOLDER TO BE PROTECTED AuthType Basic AuthName "Password Required" AuthUserFile FOLDER\.htpasswd Require valid-user

HTPASSWD & HTACCESS

01

NEW XMLHTTP OBJECT var xhr = new XMLHttpRequest(); xhr.open("GET", "FOLDER/PAGE");

AJAX WITH HTTP AUTH

02

APPEND USER & PASSWORD var token = "Basic" +   window.btoa(NAME+":"+PASSWORD); xhr.setRequestHeader   ("Authorization", token);

GO! xhr.send();