1
我沒有在html頁面中獲取數據。 home.html的AngularJS jsonp不適用於我
<!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;
});
}
});
您的HTML頁面中沒有任何「
直到你包含angular.js文件,就像普通的html頁面一樣。
使用下面的代碼來運行這個頁面作爲角度的應用程序。
來源
2016-12-02 04:46:06