Reputation: 169
I currently have the following angular script in a page:
var app = angular.module('doorman', []);
app.controller('formCtrl', function($scope, $http) {
$scope.create = function() {
var msg = '{' +
'"id":"id",' +
'"building":"' + $scope.building + '",' +
'"unit":"' + $scope.unit + '",' +
'"firstName":"' + $scope.firstName + '",' +
'"name":"' + $scope.name + '",' +
'"carrier":"' + $scope.carrier + '",' +
'"tracker":"' + $scope.tracker + '"' +
'"delivered":"0",' +
'"added":"NOW()"' +
'}';
$http.put("104.131.166.246:8080/doorman/rest/pilot", msg).
success(function(data, status, headers, config) {
//empty the fields
$scope.building = "";
$scope.unit = "";
$scope.firstName = "";
$scope.name = "";
$scope.carrier = "";
$scope.tracker = "";
}).
error(function(data, status, headers, config) {
//TODO temporary, remove
alert("ERROR " + status + ": " + data);
});
};
$scope.search = function() {
}
});
I have a backend RESTful java servlet handling requests. When I call the 'create()' function, the output always ends up on the error function, showing the alert 'ERROR undefined: undefined'. While monitoring http requests on chrome, I see no request being made at all. What could the problem be?
Upvotes: 1
Views: 230
Reputation: 169
Found the error. Apparently, appending "http://" to the beginning of the url is necessary. Thanks anyway!
Upvotes: 0
Reputation: 1820
From angular side, your code looks ok. Further when you say the call ends up in the error section, it suggest that something is going wrong on the outbound call or on the server side. Can you use browser tools or if you are in windows use a tool like fiddler to see the network traffic to see what’s going on. One
other thing, see whether you have to enable Cross-origin Resource Sharing (CORS) on server side.
Cheers
Upvotes: 0