获取 WordPress API 调用 :: 如何让它实际显示在页面上
Fetch WordPress API call :: how to get it to actually display on the page
https://codepen.io/Mortiferr/pen/XYNLpK?editors=1011
我正在尝试让帖子在此处显示,但似乎无法正常工作。如果我 console.log data[0].title
它会工作并提供我要求的数据。但是当我尝试在页面上显示它时......没有骰子。有关详细信息,请参阅代码笔。
看起来 data.title
是一个内部有 rendered
的对象。
data[0].title.rendered
会完成工作
$(document).ready(function(){
fetch('https://www.perfectimprints.com/blog/wp-json/wp/v2/posts/')
.then(response => response.json())
.then(data => {
// Here's a list of repos!
$("#postTitle").append(data[0].title.rendered);
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="postDate"></div>
<div id="postTitle"></div>
https://codepen.io/Mortiferr/pen/XYNLpK?editors=1011
我正在尝试让帖子在此处显示,但似乎无法正常工作。如果我 console.log data[0].title
它会工作并提供我要求的数据。但是当我尝试在页面上显示它时......没有骰子。有关详细信息,请参阅代码笔。
看起来 data.title
是一个内部有 rendered
的对象。
data[0].title.rendered
会完成工作
$(document).ready(function(){
fetch('https://www.perfectimprints.com/blog/wp-json/wp/v2/posts/')
.then(response => response.json())
.then(data => {
// Here's a list of repos!
$("#postTitle").append(data[0].title.rendered);
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="postDate"></div>
<div id="postTitle"></div>