问题
I'm trying to get JSON through an API but it keeps giving me
Response for preflight has invalid HTTP status code 401
This is my code
$.ajax({
beforeSend: function (request)
{
request.withCredentials = true;
request.setRequestHeader("Authorization", "Basic" + btoa("usernamehere:keyhere"));
},
crossDomain: true,
contentType: 'application/json',
url: url,
With the username and key different ofcourse.
I've tried without btoa, i've tried using headers:
and I've edited the CORS.
But nothing works, it just keeps throwing the same error over and over eventhough I can login with the credentials if I go to the url.
回答1:
contentType: 'application/json'
Was not allowed, that fixed it.
来源:https://stackoverflow.com/questions/36764742/jquery-ajax-keep-getting-401-response