更好的方式来在数据库角插入数据 [英] better way to insert data in database with angular

查看:81
本文介绍了更好的方式来在数据库角插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有12场(或更多比)形式,我想与角度数据插入到数据库中。

i have a form with 12 field (or more than that) and i want to insert data with angular to database .

我知道方法是什么:

$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各领域这样的定义每一个所有数据的方式:

but i'm looking for a way that post all data from form whitout define each by each field like this :

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

有没有办法做到这一点?

is there any way to do this ?

推荐答案

您可以使用一个数组来更好地组织code

You can use an array to better organize the code

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);
          }  
}

这篇关于更好的方式来在数据库角插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆