0
我正在尝试使用API从维基百科获取数据。Javascript维基百科概要提取错误
这里是最初的代码卡:
$(document).ready(function() {
var searchTerm = document.title;
$.getJSON("https://en.wikipedia.org/w/api.php?action=parse&page=" + searchTerm + '&prop=text&format=json&callback=?', function(json) {
$('#wikiInfo').html(json.parse.text['*']);
$("#wikiInfo").find("a:not(.references a)").attr("href", function() {
return "http://www.wikipedia.org" + $(this).attr("href");
});
$("#wikiInfo").find("a").attr("target", "_blank");
});
});
<title>Fire</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="wikiInfo"> </div>
然而,这给了我整个页面,我寻找的东西,这将使我维基的只是概要页。 我在网上看了一下,该解决方案建议是要改变一些初始参数,使JS的样子:
var searchTerm = document.title;
$.getJSON("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&titles=" +searchTerm +'&callback=?', function(json) {
$('#wikiInfo').html(json.parse.text['*']);
$("#wikiInfo").find("a:not(.references a)").attr("href", function(){ return "http://www.wikipedia.org" + $(this).attr("href");});
$("#wikiInfo").find("a").attr("target", "_blank");
});
不过,现在我面对的错误:
Uncaught TypeError: Cannot read property 'text' of undefined
at Object.success (wikis.html:9)
at c (jquery.min.js:3)
at Object.fireWith [as resolveWith] (jquery.min.js:3)
at k (jquery.min.js:5)
at HTMLScriptElement.n.onload.n.onreadystatechange (jquery.min.js:5)
可能有人请帮助我需要改变什么?我是处理JSON数据和使用API的新手
太感谢你了!这对我有用:) – Appstarter