I am running an angularjs app and I am having trouble finding out why my $http
call is failing.
I type the url into the browser I always get a response.
But when I make there url request through $http
it fails.
My code is:
.controller('StopDetailCtrl', function($scope, $http) {
$scope.info = fetch();
function fetch(){
//This url works
// var uriBuilder = 'http://cors-test.appspot.com/test'
//This url doesn't
var uriBuilder = 'http://api.translink.ca/rttiapi/v1/stops/55612?apikey=u8RWYB3HmxjsHenpDk0u'
$http({
method: 'GET',
url: uriBuilder
}).then(function successCallback(response) {
console.log('Success', JSON.stringify(response));
}, function errorCallback(response) {
console.log('Error', JSON.stringify(response));
});
}
})
The error I keep getting back is a json string which is not informative.
{
"data": null,
"status": 0,
"config": {
"method": "GET",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http:\/\/api.translink.ca\/rttiapi\/v1\/stops\/55612?apikey=u8RWYB3HmxjsHenpDk0u",
"headers": {
"Accept": "application\/json, text\/plain, *\/*"
}
},
"statusText": ""
}
Is there something I am missing in the $http request?
The api I am using is: https://developer.translink.ca/ServicesRtti/ApiReference