Primer: I'm suck at new stuff, so I'm working my way through it as best I can. I apologize when you notice I'm probably doing everything wrong.
Here I am, I've got an app that has a few REST endpoints that spit out some json. I know they work quite nicely because I can throw the uri in a browser and see the json that gets spit out. So I decided to try my hand at some Angular and see if I could consume said json. A quick and dirty test controller hits my endpoint, but the $http.then always hits the failure condition with a null response object. I've verified that my REST service is sending actual content, and as mentioned the same uri spits out the proper json in a browser address bar. I'm at a loss.
Code sample time:
CallRest() is tied to a HTML button/ng-click, and then the response data is supposed to get spit out to a thingee on the page. No matter what I try I get a null object for response.data and a -1 for response.status. I'm at a loss.
Feel free to scoff. Angular and JS is completely not my cup of tea. I'm just trying something new here and even getting it to talk to the endpoint is a miracle imho. Appreciate any tips.
Here I am, I've got an app that has a few REST endpoints that spit out some json. I know they work quite nicely because I can throw the uri in a browser and see the json that gets spit out. So I decided to try my hand at some Angular and see if I could consume said json. A quick and dirty test controller hits my endpoint, but the $http.then always hits the failure condition with a null response object. I've verified that my REST service is sending actual content, and as mentioned the same uri spits out the proper json in a browser address bar. I'm at a loss.
Code sample time:
Code:
var app = angular.module('test', []);
app.controller('testcontroller', function($scope, $http) {
$scope.CallRest = function() {
var testreq = encodeURIComponent(JSON.stringify({})); // add an empty json object to the uri
var req = {
method: 'GET',
url: 'http://localhost:8088/restthing/endpoint?request=' + testreq
}
$scope.uri = req.url;
$http(req).then(function (response) {
alert('Success');
$scope.json = angular.toJson(response.data);
$scope.status = response.status;
}, function (response) {
alert('Failed');
$scope.json = angular.toJson(response.data);
$scope.status = response.status + ' ' + response.statusText;
});
}
});
CallRest() is tied to a HTML button/ng-click, and then the response data is supposed to get spit out to a thingee on the page. No matter what I try I get a null object for response.data and a -1 for response.status. I'm at a loss.
Feel free to scoff. Angular and JS is completely not my cup of tea. I'm just trying something new here and even getting it to talk to the endpoint is a miracle imho. Appreciate any tips.