2016-11-08 4 views
1

Ich bekomme nicht die Daten in HTML-Seite. home.htmlAngularJS jsonp funktioniert nicht für mich

<!Doctype html> 

<html ng-app="myServiceApp"> 

<head>  
    <title>Processing $http.jsonp() response in service</title>   
</head> 

<body> 

<div ng-controller="myServiceCtrl"> 

    <h3>Processing $http.jsonp() response in service</h3> 

    <button ng-click="doJSONPRequest()">Click and make JSONP request</button>  
    <p>Data Details: {{details}}</p>  
    <p>Status Code: {{statcode}}</p>  
</div>  
</body> 
</html> 

myServiceCtrl.js

var app = angular.module('myServiceApp', []); 

app.controller('myServiceCtrl', function ($scope, $http) { 

    $scope.doJSONPRequest = function() { 

     var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK"; 

     $http.jsonp(url) 

      .success(function (data, status, headers, config) { 

       $scope.details = data.found; 

       $scope.statcode = status; 

      }) 

      .error(function (data, status, headers, config) { 

       $scope.statcode = status; 

      }); 

    } 

}); 
+0

Sie haben keine ''

1

Bis Sie angular.js Datei enthalten ist es wie normale HTML-Seite.

Verwenden Sie diesen unteren Code, um diese Seite als eckige App auszuführen.

<!DOCTYPE html> 
<html> 
<head>  
    <title>Processing $http.jsonp() response in service</title>   
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
    <script> 
    var app = angular.module('myServiceApp', []); 
     app.controller('myServiceCtrl', function ($scope, $http) { 

      $scope.doJSONPRequest = function() { 

       var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK"; 

       $http.jsonp(url) 

        .success(function (data, status, headers, config) { 

         console.log(data) 
         $scope.details = data.found; 
         $scope.statcode = status; 

        }).error(function (data, status, headers, config) { 

         $scope.statcode = status; 

        }); 

      } 

     }); 
    </script> 

</head> 

<body> 
    <div ng-app="myServiceApp" ng-controller="myServiceCtrl"> 
     <button ng-click="doJSONPRequest()">Click and make JSONP request</button>  
     <p>Data Details: {{details}}</p>  
     <p>Status Code: {{statcode}}</p>  
    </div>  
</body></html> 
Verwandte Themen