It seems that jQuery does not send an Authorization header when sending an OPTIONS request before a POST request (or possibly other types). The server I am trying to reach returns 401 status for an OPTIONS request - how can I get jQuery to include the Authorization header even in this initial request?
$.ajax({ type: "POST", url: url, data: postData, beforeSend: function ajaxBeforeSend(jqXHR) { jqXHR.withCredentials = true; jqXHR.setRequestHeader("Authorization", "Basic " + btoa(encodeURIComponent(escape($username.val())) + ":" + encodeURIComponent(escape($password.val())))); }, success: runReportUrlCallback, error: runReportErrorCallback });
I also tried adding username and password to ajax options, but to no avail.
source share