【发布时间】:2018-08-13 14:40:01
【问题描述】:
我正在尝试使用 AJAX 请求令牌。这只会在 localhost 上用于发出请求。我有代码:
$.ajax({
url: "TOKEN URL HERE",
beforeSend: function(xhr) {
xhr.setRequestHeader("grant_type", "client_credentials");
xhr.setRequestHeader("client_id", "ENTER CLIENT ID");
xhr.setRequestHeader("client_secret", "ENTER CLIENT SECRET");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
},
dataType: "json",
//content-Type: "application/json",
type: "POST",
success: function(response) {
token = response.access_token;
expiresIn = response.expires_in;
},
error: function(errorThrown) {
alert(errorThrown.error);
}
});
但是,它不起作用。这是正确的方法还是我的参数不正确? (或者 AJAX/JQuery/JS 无法请求 OAuth2 令牌)
【问题讨论】:
-
如果它适合你,请检查它stackoverflow.com/a/62317987/7225569
标签: javascript jquery ajax oauth-2.0