I am learning angularJS and trying to implement it in my application.
I have a RESTful WCF service hosted on local IIS. It has a GET method defined to get the list of documents: http: // localhost: 70 / DocumentRESTService.svc / GetDocuments /
Now I am trying to use this service in my angular application and display data. The following is the code: HTML:
<html>
<script src="../../dist/js/angular/angular.min.js"></script>
<script src="../../assets/js/one.js"></script>
<body ng-app="myoneapp" ng-controller="oneAppCtrl">
{{"Hello" + "AngularJS"}}
<hr>
<h1> Response from my REST Service </h1>
{{hashValue}}
<hr>
<h1> Response from w3school REST Service </h1>
{{names}}
</body>
</html>
JS:
angular.module('myoneapp', [])
.controller('oneAppCtrl', function($scope,$http){
$scope.documentValue = {};
$http({method: 'GET',
url: 'http://localhost:70/DocumentRESTService.svc/GetDocuments/',
headers:
{
}
})
.success(function(data){ alert('Success!'); $scope.documentValue=data;})
.error(function(data){ alert('Error!'); $scope.documentValue=data; alert('Error!' + $scope.documentValue);})
.catch(function(data){ alert('Catch!'); $scope.documentValue= data;});
$http.get("http://www.w3schools.com/angular/customers.php")
.success(function(response) {$scope.names = response.records;});
});
The strange behavior of this code works fine in IE11, while it does not run in Chrome / Firefox.
The answer below is in chrome: (for my REST service), while the REST service from w3schools worked just fine.
{ "": , "": 0, "": { "": "GET", "transformRequest": [] "transformResponse": [], "URL":" http://localhost:70/DocumentRESTService.svc/GetDocuments/", "headers": { "Accept": "application/json, text/plain,/" }}, "statusText": "" }
.
XMLHttpRequest http://localhost:70/DocumentRESTService.svc/GetDocuments/. "Access-Control-Allow-Origin". ://' .
XMLHttpRequest http://localhost:70/DocumentRESTService.svc/GetDocuments/. "Access-Control-Allow-Origin". http://127.0.0.1:55969 ', , .
: http://localhost:70/DocumentRESTService.svc/GetDocuments/. , CORS.
:
- localhost ? , ?
- - , , ? , WCF? ( - )
- JSONP ? , ? , ? ( , , resarching , , .)
.
P.S:
- IDE: Brackets, .
- AngularJS v1.4.3
- stackoverflow, (CORS), $resource, $provider, $config. . - .