Hi!
I am trying to resolve a JSON Get request to my app, but I couldn’t do it no matter what.
I even tried to link to a direct json file in the www route but nothing.
Update
I got the issue fixed by using $resource thank’s to gamrziou. The app works fine when using a local JSON file
I am now able to receive JSON Rest requests, but the service treats every character as an object itself.
My sercvices.js is now like:
angular.module('starter.services', [])
.factory('Recettes', ['$resource',
function($resource){
return $resource('http://localhost/celia/web/getproduit/v100:produit', {}, {
'query': { method:'GET', isArray:false }
});
}]
);
The controller:
.controller('DashCtrl', function($scope,Recettes, prod) {
$scope.produits = Recettes.query();
})
And here is the request-response headers:
Request header Using a chrome extension
CSP: active
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36
Content-Type: text/plain; charset=utf-8
Accept: */*
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=0.2
Response header
Date: Tue, 21 Jul 2015 08:24:50 GMT
Server: Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8
X-Powered-By: PHP/5.6.8
Cache-Control: no-cache
Content-Length: 248
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json
Finally the recieved JSON:
"[{"id":2,"nom":"test32","marque":{"nom_marque":"Aucune Marque"},"est_autorise":false,"description":"TEST"},{"id":1,"nom":"none","marque":{"nom_marque":"Aucune Marque"},"est_autorise":true,"description":"none"}]"
To explain more when the page loops through “produits” in my view, it generates 248 elements same as the Content-Length: 248 in the respond header.