我设法为http.post方法编写了一个代码,如下所示使用AngularJS将数据发布到表单中,
app.controller("TodoListController", ['$scope', '$http', function($scope, $http) {
$scope.validateCredentials = function(){
var form_data = {
userName: $scope.todoName,
locations: [$scope.todoLocation]
};
//console.log(form_data);
var res = $http.post('http://127.0.0.1:8302/api/db-service/farmer/db/add', form_data);
res.then(function successCallback(data, status, headers, config) {
$scope.message = data;
res.sendStatus(200);
});
res.then(function errorCallback(data, status, headers, config) {
alert( "failure message: " + JSON.stringify({data: data}));
});
};
}]);
当我尝试将数据添加到表单中时,出现以下错误。
angular.js:15635可能未处理的拒绝:{“ data”:null,“ status”:-1,“ config”:{“ method”:“ POST”,“ transformRequest”:[null], “ transformResponse”:[null],“ jsonpCallbackParam”:“ callback”,“ url”:“ http://127.0.0.1:8302/api/db-service/farmer/db/add”,“ data”:{“ userName“:” John“,” locations“:[” Uganda“]},” headers“:{” Accept“:” application / json,text / plain, / “,” Content-Type “:” application / json; charset = utf-8“}},” statusText“:”“,” xhrStatus“:”错误“}
对此表示感谢的任何指导。
谢谢。