How to display JSON data from a link in HTML?

You need to create a html page which will get JSON data and display in HTML.
There is such code:



 <meta charset="windows-1251">
 <script src="http://code.jquery.com/jquery-latest.js"></script>
 <meta charset="utf-8">
<title></title>




 <script type="application/javascript"> 
 $(document).ready(function() {

 var url="http://website.com/api/get_recent_posts/";
 var buttonHtmlString = "", pageHtmlString = "";

 var jsonResults;

$.getJSON(url,function(data){
 jsonResults = data.posts;
 displayResults(); 
});

 function displayResults() {

 for (i = 0; i < jsonResults.length; i++) {

 pageHtmlString += " + jsonResults[i].content + ";
}
}
});
 </script> 





Website on Wordpress. Installed the plugin JSON API.
Thank you.
July 8th 19 at 11:34
1 answer
July 8th 19 at 11:36
.controller('eventsCtrl', function($scope,$http) {

 $scope.posts = [];
var wordpressUrl = "http://yoursite.com/wp-json/wp/v2/posts?categories=19";

$http.get(wordpressUrl)
.success(function(response){
 console.log("Reveived via getPosts HTTP: ", response, status);
 angular.forEach(response, function(child){ 
$scope.posts.push(child);
});
})
 .error(function(response, status){
 console.log("Error while received response. "+ status + response);
});

})

Find more questions by tags AJAXHTMLjQueryJSONWordPress