Answer the question
In order to leave comments, you need to log in
How to output JSON data from a link to HTML?
You need to create an html page that will receive JSON data and output it to HTML.
There is this code:
<!DOCTYPE html>
<html>
<head>
<meta charset="windows-1251" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<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>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
.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 getPosts via HTTP: ", response, status);
angular.forEach(response, function(child){
$scope.posts.push(child);
});
})
.error(function(response, status){
console.log("Error while received response. " + status + response);
});
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question