Currently, I am exploring Angular and attempting to utilize the POST method for my REST API calls. Below is the function found in my typeCtrl.js file:
$scope.submit = function() {
alert("add new type [" + $scope.newtype + "]" );
$http.post("http://192.168.1.115:8080/type/add", { 'type': $scope.newtype}, {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).then(function(response) {
console.log(response);
console.log(response.data);
});
$http.get("http://192.168.1.115:8080/type").then(function(response) {
console.log(response);
console.log(response.data);
$scope.all_types = response.data;
});
};
The line
alert("add new type [" + $scope.newtype + "]" );
successfully triggers as expected, confirming that $scope.newtype
contains a value.
Upon reviewing the output from my node.js backend, the following results are displayed:
POST /type/add 200 2.267 ms - 73
GET /type 200 23.854 ms - 6465
GET /type 304 22.217 ms - -
undefined
{ '{"type":"aaaa"}': '' }
POST /type/add 200 1.863 ms - 73
GET /type 200 26.053 ms - 6508
undefined
{ '{"type":"zzzzzzz"}': '' }
POST /type/add 200 1.734 ms - 73
GET /type 200 25.389 ms - 6551
undefined
{ '{"type":"zzzzzzz"}': '' }
POST /type/add 200 2.142 ms - 73
GET /type 200 25.435 ms - 6594
I suspect there might be an issue with how I am setting up the data
. Could someone kindly assist me in identifying where I may be going wrong?