ich möchte konverg zu ajax zu locken.conver zu Ajax zu curl -> curl localhost: 8080/oauth/Token -h foo: bar -d grant_type = passwort -d [email protected] -d passwort = 1
curl localhost: 8080/oauth/Token -h foo: bar -d grant_type = Passwort -d [email protected] -d password = 1
Der obige Befehl erfolgreich ist.
aber Ajax scheitern ...
$.ajax({
url: 'http://localhost:8080/oauth/token',
type: 'POST',
dataType: 'json',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic' + btoa('foo:bar'));
},
data: {
grant_type: 'password',
username: '[email protected]',
password: '1'
},
complete: function(result) {
console.log('complete', result);
},
success: function(result) {
console.log('success', result);
},
error: function(result) {
console.log('error', result);
}
});
I umgewandelt Ajax und die folgenden Fehler angezeigt.
Antwort für Preflight hat ungültige HTTP-Statuscode 401
responseJSON: undefined
Was ist das Problem?