0
這是我第一次使用角度來對我的REST APU進行POST方法調用。 這是我typeCtrl.js文件中的函數:爲什麼我的角度提交功能沒有添加空數據
$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;
});
};
的alert("add new type [" + $scope.newtype + "]");
按預期執行,所以我知道,$scope.newtype
有一個值。
輸出從我的Node.js後端看起來是這樣的:
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
我不認爲我是正確設置我的data
。任何人都可以請指出我做錯了什麼?