User53449276 posted
Hi, I created an autocomplete() ajax call to return Json data from my controller to the View. But the application is protected in Basic Authentication folder. User is required to login using their domain username and password. So I got 401 error when calling
controller action. I searched online and found solution about beforeSend but I don't know how to use it in my function. Thanks. Below is my ajax code:
$(document).ready(function () {
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
},
//load expertises
$("#Keywords").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Home/GetExpertiseList",
type: "POST",
dataType: "json",
data: { searchstr: request.term },
success: function (data) {
response($.map(data,
function (item) {
return { value: item};
}));
}
});
},
messages: {
noResults: "", results: ""
}
});
})