簡體   English   中英

如何編寫最簡單的jQuery從Wikipedia API獲取數據?

[英]How to write the simplest jQuery to fetch data from 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>

您應該添加&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);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM