【发布时间】:2018-06-07 17:23:37
【问题描述】:
我想将 ajax 转换为 curl。
curl localhost:8080/oauth/token -h foo:bar -d grant_type=password -d username=test@gmail.com -d password=1
以上命令成功。
但是 ajax 失败了...
$.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: 'test@gmail.com',
password: '1'
},
complete: function(result) {
console.log('complete', result);
},
success: function(result) {
console.log('success', result);
},
error: function(result) {
console.log('error', result);
}
});
我转成ajax,出现如下错误。
预检响应包含无效的 HTTP 状态代码 401
responseJSON:未定义
有什么问题?
【问题讨论】: