In order to preemptively send authentication without a 401 Unauthorized response, use 'headers' as given below:
$.ajax
({
type: "GET",
url: "index.htm",
dataType: 'json',
async: false,
headers: {
"Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
},
data: '{ "comment" }',
success: function (){
alert('Thanks for your comment!');
}
});