0
我試圖發送一個POST請求Yelp的API使用這些指令來獲得訪問令牌:https://www.yelp.com/developers/documentation/v3/get_started如何調用訪問令牌的Yelp API?
但是,下面的代碼不打印任何東西到控制檯。我不確定問題所在,或者我已經正確設置了POST請求。我的代碼有什麼問題? :(
foodfinder.html:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="./public/foodfinder.js"></script>
<meta charset="UTF-8">
<title>Food Finder</title>
</head>
<body>
Hello world
</body>
</html>
foodfinder.js:
$(function() {
var API_HOST = "api.yelp.com";
var SEARCH_PATH = "/v3/businesses/search";
var BUSINESS_PATH = "/v3/businesses/";
var TOKEN_PATH = "/oauth2/token";
var GRANT_TYPE = "client_credentials";
var CLIENT_ID = "abc"; // dummy id for stackoverflow purposes
var CLIENT_SECRET = "xyz"; // dummy secret for stackoverflow purposes
var SEARCH_TERM = "food";
var SEARCH_RADIUS = 500; // radius is in meters
var SORT_BY = "distance";
$.ajax(API_HOST + TOKEN_PATH, {
type: "POST",
data: {
grant_type: GRANT_TYPE,
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET
},
contentType: "application/x-www-form-urlencoded",
dataType: "json",
success: function (data) {
console.log(data);
},
error: function() {
console.log("post call error");
}
})
});