I tested code in this post and modified a bit for my use. But I cannot get JSON object from API of my blog that I have generated using WordPress JSON plugin.
- URL API from BLOG (NOT WORKING): http://teckstack.com/api/get_recent_posts
- URL from W3C example (WORKING): http://www.w3schools.com/website/Customers_JSON.php
I stuck when tried to manipulated JSON API from my blog (mentioned above) and the same code worked for the other url provided by w3c example?
Please provide your suggestion.
I am using below codes in .html file and not in WordPress environment.
==== Angular JS Script ====
(function() {
var app = angular.module('tsApp', []);
app.controller('TSController', function($scope, $http) {
$scope.heading = [];
$http({
method: 'GET',
url: 'http://teckstack.com/api/get_recent_posts'
}).success(function(data) {
console.log("pass");
$scope.heading = data; // response data
}).error(function(data) {
console.log("failed");
});
});
})();
==== HTML ====
<html ng-app="tsApp">
<body ng-controller="TSController as tsCtrl">
<article class="main-content" role="main">
<section class="row">
<div class="content">
<div class="name-list">
<h1>Dummy Title</h1>
<ul>{{ 1+1 }} (Testing AJS is working)
<li ng-repeat="title in heading" class="">
<h3>{{title.Name}}</h3>
</li>
</ul>
</div>
</div>
</section>
</article>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
I am raising this question after checking for all solution online https://stackoverflow.com/a/26898082/1841647 and http://www.ivivelabs.com/blog/fix-cross-domain-ajax-request-angularjs-cors/ But nothing worked for me.
Creating JSFiddle for your convenience: http://jsfiddle.net/236gdLnt/