javascript - Manipulate Data with JSON using Angular JS for WordPress JSON API -


i tested code in this post , modified bit use. cannot json object api of blog have generated using wordpress json plugin.

  1. url api blog (not working): http://teckstack.com/api/get_recent_posts
  2. url w3c example (working): http://www.w3schools.com/website/customers_json.php

i stuck when tried manipulated json api blog (mentioned above) , same code worked other url provided w3c example?

please provide suggestion.

i using below codes in .html file , 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 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 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 raising question after checking solution online https://stackoverflow.com/a/26898082/1841647 , http://www.ivivelabs.com/blog/fix-cross-domain-ajax-request-angularjs-cors/ nothing worked me.

creating jsfiddle convenience: http://jsfiddle.net/236gdlnt/

it's cross-domain issue. can first url data rquesting jsonp. angular support $http.jsonp method:

$http.jsonp('http://teckstack.com/api/get_recent_posts?callback=json_callback')    .success(function (data1) {         console.log("blog pass");         $scope.heading1 = data1; // response data      }).error(function (data1) {         console.log("blog failed");     }); 

make sure add callback=json_callback parameter url.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -