In fact, you should be able to pass the user and password using the properties userand passwordin the object options.
In previous versions of Dojo, this has been documented, but it seems that now it is not. However, I just tested it and seemed to add a username and password to the url, like this:
http://user:password@myUrl/example.json
URL-, .
, , :
xhr("example.json", {
headers: {
"Authorization": "Basic " + base64.encode(toByteArray(user + ":" + pass))
}
}).then(function(data) {
});
dojox/encoding/base64 :
var toByteArray = function(str) {
var bytes = [];
for (var i = 0; i < str.length; ++i) {
bytes.push(str.charCodeAt(i));
}
return bytes;
};