我试图通过NBA.com的AJAX(jQuery)请求json文件
我首先尝试获取json文件,但遇到了CORS错误,所以我尝试使用jsonp
这会返回一个对象,但对象看起来像是充满了函数和方法,而不是我请求的数据。
我在codepen上做了这个,所以你可以检查出来,可以用开发者控制台检查输出,因为document.write只返回[object Object]
这是指向codepen的链接:http://codepen.io/kyriediculous/pen/KNKZZL
$(document).ready(function() {
function getPlayerGameLogs() {
$.ajax ({
url: "http://stats.nba.com/stats/commonplayerinfo?LeagueID=00&PlayerID=202355&SeasonType=Regular+Season&format=jsonp",
dataType:"jsonp",
success: function(response) {
console.log(response);
}
})
};
getPlayerGameLogs();
});
有人可以解释一下吗?是否无法从nba.com请求JSON?特别是游戏记录每个玩家。
答案 0 :(得分:3)
你的例子很好用。
body {
font-family: sans-serif;
}
table {
border: 1px solid gray;
font-size: 11px;
border-collapse: collapse;
}
td, th {
border: 1px solid gray;
padding: 2px;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head></head>
<body>
<h3>Headline Stats</h3>
<table id="PlayerHeadlineStats"></table>
<br />
<h3>Player Info</h3>
<table id="CommonPlayerInfo"></table>
</body>
</html>
&#13;
{{1}}&#13;