This might be a little bit of a stretch, but let's just assume that we need it to work this way:
Can I submit credentials for basic authentication with an AJAX request?
xmlHttpRequest.setRequestHeader is your friend.
xhr.setRequestHeader("Authentication", "username:password in base64")
you just need to convert username:password to base64