这是我执行 post 功能的 Angular Controller
app.controller ('accountsCtrl', function($scope, $http) {
this.accounts = { code:"", account_name:"", description:"", account_type_id:"", is_active:"", user_id:"", owner_id:""};
$scope.addPage = "#!/account";
$scope.uploadPage = "upload.html";
$scope.exportPage = "export.html";
let user_token = local_store("get", "primalfitsUser").token;
let headers = {
"Content-Type":'application/x-www-form-urlencoded;charset=utf-8;',
"Authorization":"Bearer "+user_token
};
$scope.account_save = function($http) {
this.accounts.is_active = 1;
console.log(this.accounts);
// $http.post(base_api_url+"/accounts",$httpParamSerializerJQLike(this.accounts) ,{"headers":headers}).then(
// result => console.log(result)
// ).catch(error => console.log(error));
$http({
url: base_api_url+"/accounts",
method: "POST",
headers: headers,
data: {'message' : this.accounts},
paramSerializer: '$httpParamSerializerJQLike'
}).then((result) =>{
$scope.info = result.data.message;
}, function(error){
$scope.error = error;
});
};
最佳答案
您正在定义一个 $http
局部变量,也许这就是问题所在?
$scope.account_save = function($http) { // <- remove $http! it comes from the controller itself
this.accounts.is_active = 1;
console.log(this.accounts);
关于javascript - AngularJs $http post 不发送数据到restful api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73608340/