これは私を少しイライラさせてしまった。 JSONデータをリンク上で実行するための快適なサービスを提供しています。http://localhost:51133/API/SalesSystem/AngularJSがデータなしでjson rest serviceを使用して奇妙な応答を得る
WPFベースのインターフェイスを使用して問題なくこのサービスからデータを取得できます。 http://rest-service.guides.spring.io/greeting
しかし、私自身のサービスから何かが間違って何とか行くようだと私は間違って何が起こるのかを把握することはできません。
私がテストしてい別のサービスは、この1です。 Springサービスは応答関数を使って私に応答しますが、私のサービスは成功関数関数を使って応答します。とても混乱するような。
レスポンスがあると思われる:
{"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"http://localhost:51133/API/SalesSystem/","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"","xhrStatus":"error"}
私はそれを見て、私がCORSを有効にするために必要となる可能性があるように見えたが、私はどのように完全にわかりません。私はNuGetからインストールしました。サービスはVisual Studioで実行されていて、config.EnableCors()を追加しました。私のWebApiConfigに送ってください。
私のJSスクリプト:
angular.module('demo', [])
.controller('Hello', function ($scope, $http) {
$http.get('http://localhost:51133/API/SalesSystem/')
//http://rest-service.guides.spring.io/greeting
//http://localhost:51133/API/SalesSystem/
.then(function (response) {
$scope.hello = 'hello';
$scope.district = response.data;
console.debug(response.data);
console.log(response.data)
}, function success(response) {
$scope.hello = 'hello2';
$scope.district = response;
$scope.rep = response.data;
console.debug(response.data[0]);
$scope.district = response.data[0];
console.log(success.data)
}, function error(response) {
$scope.hello = 'hello3';
$scope.district = error.data;
console.log(error.data)
});
});
私のhtml:
<!doctype html>
<html ng-app="demo">
<head>
<title>Hello AngularJS</title>
<script src="Scripts/angular.min.js"></script>
<script src="Scripts/hello.js"></script>
</head>
<body>
<div ng-controller="Hello">
<li>Id: <button>{{hello}}</button></li>
<li>Area: {{district}}</li>
<ul ng-repeat="obj in hello">
<li>Area: {{obj.area}}</li>
</ul>
<p>The ID is {{rep.Id}}</p>
<p>The content is {{hello.Area}}</p>
</div>
</body>
</html>
が、私は私のWPFベースのフロントエンドは、それは文句を言わないAngularJSで動作する理由は、わからないこのサービスを使用して動作するようにそれをすべて取得しています。
可能な重複/ question/46958146/not-getting-json-rest-in-my-angularjs-application) –