I have kind of a strange problem. Was looking everywhere but cannot find any solution. It is my first time with angular.js and I'm trying to get content from an API into my Angular App.
The Success Message works but the (data) is empty. If I change the GET URL to the one from w3Schools http://www.w3schools.com/website/Customers_JSON.php it works. So I'm not sure if my request URL http://fingerzeig.ch/api/agenda/list is formatted properly neither do i know if i need to decode or encode the data. If i compare the two pages i noticed that the fingerzeig URL is a little bit different.
Any help would be appreciated.
Here is my code myapp.js:
var app = angular.module("MyApp", []);
app.controller("PostsCtrl", function($scope, $http) {
$http.get('http://fingerzeig.ch/api/agenda/list').
success(function(data, status, headers, config) {
console.log("success!");
console.log(data);
$scope.posts = data;
}).
error(function(data, status, headers, config) {
// log error
});
});
And here the HTML:
<body ng-app="MyApp">
<div ng-controller="PostsCtrl">
<ul ng-repeat="post in posts">
<li>{{post.ID}}</li>
</ul>
</div>
</body>
And here the links:
http://www.w3schools.com/website/Customers_JSON.php => WORKING
http://fingerzeig.ch/api/agenda/list => NOT WORKING
Here are the fiddels: One with my request url with i want to make work. One with the example url from w3 schools. Only the GET url's are changed.
Fiddle not working: link
The one who works link
Thank you very much!
This is probably a cross-domain issue. Note that http://www.w3schools.com/website/Customers_JSON.php
has the Access-Control-Allow-Origin: *
response header and http://fingerzeig.ch/api/agenda/list
does not.
$ curl -I "http://www.w3schools.com/website/Customers_JSON.php"
If you're making a cross-domain request you have to deal with CORS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.