如何使用ajax get方法显示博客中的帖子总数

时间:2018-02-13 11:52:37

标签: json ajax blogger

我想要显示总数。在博客中使用ajax get方法的帖子是我的代码。

<div id='show'></div>
<script type="text/javascript">
$.ajax({
url: "https://techtovillage.blogspot.com/feeds/posts/default?orderby=published&max-results=10&start-index=2&alt=json-in-script",
type: "get",
dataType: "jsonp",
success: function (data) {
var Posts = '<div class="hindipathtestapp">';
for (var i = 0; i < data.feed.entry.length; i++) {
var totalposts = json.feed.openSearch$totalResults.$t;
var posttitle = data.feed.entry[i].title.$t;
var postcontent = data.feed.entry[i].content.$t;
Posts += "<div class='testapp'><h1>" + totalposts + "</h1><h3>" + posttitle + "</h3><div class='content'>" + postcontent + "</div></div>";
}
Posts += "</div>"
document.getElementById('show').innerHTML = Posts;
}
});
</script>

1 个答案:

答案 0 :(得分:0)

试试这个

<div id='show'></div>
<script type="text/javascript">
    $.ajax({
    url: "https://techtovillage.blogspot.com/feeds/posts/default?alt=json-in-script",
    type: "get",
    dataType: "jsonp",
    success: function (data) {
        var totalposts = data.feed.openSearch$totalResults.$t;
        document.getElementById('show').innerHTML = "<div class='totalposts'>" + totalposts + "</div>";
        }
    });
</script>