在得到我使用jQuery从这里http://quotes.rest/qod.json作出JSON请求,我不断在日志中收到此错误。这是否重要,我该如何摆脱它?最后,为什么我“米不显示在页面上任何东西。我可以看到日志的报价。为什么不能在网页上?我错过什么?谢谢我怎么能摆脱掉这个错误,为什么我不能在页面
Uncaught ReferenceError: json is not defined
at HTMLButtonElement.<anonymous> (VM1741 pen.js:9)
at HTMLButtonElement.dispatch (VM1796 jquery.min.js:3)
at HTMLButtonElement.q.handle (VM1796 jquery.min.js:3)
,这是我的jQuery代码
$(document).ready(function() {
/*getting random quote on button click*/
$('#getMessage').on("click", function() {
$.getJSON("https://quotes.rest/qod.json", function(json) {
console.log(json.contents.quotes[0])
var quoteArr = json.contents.quotes[0];
console.log(quoteArr.quote)
console.log(quoteArr.author)
});
$("#quote-content").html(quoteArr.quote);
$("#quote-author").html(quoteArr.author);
});
});
您的两个朝向底线('$(..)。html')应该是'$ .getJSON'回调函数中。这可能是你没有看到任何东西的原因。 –