I have encountered an issue while attempting to send a POST request to a server with a different domain that necessitates basic authentication.
Despite my best efforts in experimenting with beforeSend and withCredentials, the basic auth headers do not get included in the OPTIONS preflight request.
$.ajax({
url: anotherdomain,
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
dataType:'json',
xhrFields: {
withCredentials: true
},
crossDomain: true,
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Basic *');
xhr.withCredentials = true;
}
I have found that changing the dataType to 'jsonp' or switching the request type to GET allows for successful completion of the request. Is removing the Basic Auth requirement from the anotherdomain server during OPTIONS requests the only viable solution?
Thank you.