0

Getting the below error:

 OPTIONS http://localhost:4444/Examples/Form net::ERR_CONNECTION_REFUSED

The Angular JS code used:

var app = angular.module('myApp', []);
app.controller('myCtrl', ['$scope', '$http', function($scope, $http) {
var enrolledUser = {};
$scope.enrolledUser = enrolledUser;
console.log("Func");
$scope.sendPost = function(){
    console.log("Func Called");
    $http.post('http://localhost:4444/Examples/Form',enrolledUser);
};
}]);

HTML Code:

<div ng-controller='myCtrl'>
 <form name="enrollform" class="css-form" novalidate >
    <label for="empNo">Employee Number* :</label>
    <input type="text" ng-model="enrolledUser.empNo" name="empNo" ng-required/> 
    <span ng-show="enrollform.empNo.$error.required">Employee Number is mandatory!!</span> 
    <button type="button" class="btn btn_success" ng-click="sendPost()">Submit</button>
</form>

Detailed Error received on console:

angular.js:12759 OPTIONS http://localhost:4444/Examples/Form net::ERR_CONNECTION_REFUSED

angular.js:14700 Possibly unhandled rejection:{"data":null,"status":-1,"config":{"method":"POST","transformRequest":[null],"transformResponse":null], "jsonpCallbackParam":"callback","url":"http://localhost:4444/Examples/Form","data":{"empNo":"1","track":"1","designation":"SE","category":"UI","subCategory":"AngularJS"},"headers":{"Accept":"application/json, text/plain, /","Content-Type":"application/json;charset=utf-8"}},"statusText":"","xhrStatus":"error"}

  • Does your server allow OPTIONS requests? – bamtheboozle Sep 25 '17 at 09:48
  • Is your angular code running on same server as the backend or it's under nodejs or similar, with different port? – pegla Sep 25 '17 at 09:50
  • I am new to angular, I am using eclipse IDE and Tomcat server for the project. – BIPIN SHARMA Sep 26 '17 at 06:35
  • Then they will be running on the same Server and coming to server allow OPTIONS requests. How to check this? and I was able to navigate to servlet and was able to see the JSON sent on Browsers' Network too. – BIPIN SHARMA Sep 26 '17 at 06:36

0 Answers0