我正在学习有关JSON的知识,并且在显示来自端点的数据时遇到问题。这第一段代码对我来说工作得很好。
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<div class="mypanel"></div>
<script>
$.getJSON('http://time.jsontest.com', function(data) {
var text = `Date: ${data.date}<br>
Time: ${data.time}<br>
Unix time: ${data.milliseconds_since_epoch}`
$(".mypanel").html(text);
});
</script>
</body>
</html>将脚本更改为此终结点不显示任何数据。如何显示此数据?
<script>
$.getJSON('https://www.halowaypoint.com/en-us/games/halo-the-master-chief-collection/xbox-one/game-history?gamertags=ice%20cold%20bepsi&gameVariant=all&view=DataOnly', function(data) {
var text = `Gamertag: ${data[0].Gamertag}`
$(".mypanel").html(text);
});
</script>发布于 2021-07-20 23:37:24
仔细研究一下,您似乎需要进行身份验证才能获得此数据。如果没有返回json,那么回调就不会运行。这就是为什么如果你在回调中放了任何东西,即使是console.log("HERE"),它也不会到达它。
如果您想要进行身份验证,则需要执行ajax请求。无论如何,$.getJSON只是$.ajax的一个包装器。
https://stackoverflow.com/questions/68457563
复制相似问题