如何编写最简单的jQuery来获取Wikipedia API的数据



helllo。我试图使用最简单的jQuery从Wikipedia API获取数据,但是到目前为止,我只在下面就达到了这一点。我该如何完成这项工作?谢谢!

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
    $.getJSON('https://en.wikipedia.org/w/api.php?action=query&titles=Conchita_Wurst&prop=revisions&rvprop=content&format=json', function(data)
    {
      $('#demo').text(data.query.normalized[0].to);
    });
});
</script>
</head>
<body>
<p id="demo"></p>
</body>
</html>

您应该在URL中添加&callback=?

$.getJSON('https://en.wikipedia.org/w/api.php?action=query&titles=Conchita_Wurst&prop=revisions&rvprop=content&format=json&callback=?', function(data)
{
  $('#demo').text(data.query.normalized[0].to);
});

最新更新