使用angular在数据库中插入数据的更好方法

时间:2014-11-29 08:45:35

标签: angularjs

我有一个12字段(或更多)的表单,我想将带有角度的数据插入数据库。

我知道方法是什么:

$http.post('post_es.php', {'uname': $scope.username, 'pswd': $scope.userpassword}
                    ).success(function(data, status, headers, config) {
                        if (data.msg != '')
                        {
                            $scope.msgs.push(data.msg);
                        }  

但是我正在寻找一种方法,从表单whitout发布所有数据,每个字段都按照以下方式定义:

{'uname': $scope.username, 'pswd': $scope.userpassword}

有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

您可以使用数组来更好地组织代码

var values = [
  'uname': $scope.username,
  'pswd': $scope.userpassword
];

$http.post('post_es.php', values).success(function(data, status, headers, config) {
        if (data.msg != '')
          {
             $scope.msgs.push(data.msg);
          }  
}