3
我想使用Ajax獲取隨機維基百科頁面的摘錄。我儘可能地獲取數據,但我無法輸出數據。獲取隨機Wikipedia提取與Ajax
這裏是我的代碼:
$.ajax({
type: "GET",
url: "https://simple.wikipedia.org/w/api.php?action=query&generator=random&grnnamespace=0&prop=extracts&exsentences=10&format=json&callback=?",
contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
success: function (data) {
console.log(data);
var text = data.parse;
document.getElementById('div_text').innerHTML = text;
},
error: function (errorMessage) {
}
});
控制檯日誌中的數據很好,但在瀏覽器中輸出僅僅是undefined
。
顯然,問題是這一行:
var text = data.parse;
我要去哪裏錯了?