I am trying to integrate angularjs with my already built app in CakePHP. When I tried to pull request from CakePHP using AngularJS I am getting response in error. Though if I hit same url I am getting valid json. I tried using addons in chrome also. But AngularJS takes it in error.
My Controller Code of AngularJS.
var load = function () {
console.log('call load()...');
console.log($rootScope.appUrl + '/songs.json');
$http.get($rootScope.appUrl + '/songs.json')
.success(function (data, status, headers, config) {
$scope.posts = data;
alert("Here");
alert(JSON.stringify($scope.posts));
angular.copy($scope.posts, $scope.copy);
})
.error(function (data, status, headers, config) {
alert("Error");
console.log('DATA : ' + data);
console.log('Status : ' + status);
console.log('headers : ' + JSON.stringify(headers));
console.log('config : ' + JSON.stringify(config));
});
}
load();
- How can I do exception handling to know what sort of error is ?
- How can I check if their is no response from server or server is off? 3.
My request headers are..
GET /demosite/songs.json HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:32.0) Gecko/20100101 Firefox/32.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: toolbarDisplay=hide
Connection: keep-alive
Response header are...
HTTP/1.1 200 OK
Date: Sat, 11 Oct 2014 03:48:34 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.4
Set-Cookie: CAKEPHP=i07rme235ifh66gjq9htdutg21; expires=Sun, 12-Oct-2014 03:48:34 GMT; Max-Age=86400; path=/; HttpOnly
Content-Length: 8717
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8
Please help.
When I check my request in XHR Console firebug its showing as OPTIONS instead of GET OR POST.
$rootScope.appUrlvalue ?