There is an API I have to access with basic authorization,
Note that I don't have access to the server where the API is stored. I cannot modify the api and is created using ASP.net,
I can view the json data when I access the api's url on the browser after providing my credentials,
however, when I'm trying to retrieve the data via AJAX request I'm getting this error
OPTIONS https://apis url/HR/api/employees 405 (Method Not Allowed)
XMLHttpRequest cannot load https://apis url/HR/api/employees.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://xxx.xx.xx.xx' is therefore not allowed access. The response had HTTP status code 405.
how do I retrieve the json data in any legal means?
here is my code
function getDataF()
{
var _token = $("input[name='_token']").val();
$.ajax({
xhrFields: {
withCredentials: true
},
headers: {
'Authorization': "Basic encryptedvalue_here"
},
url: 'https://apis url/HR/api/employees',
type: 'GET',
dataType: 'json',
contentType: "application/json",
success: function(response){
console.log(response);
}
});
}