【问题标题】:How to create an Array with AngularJS's ng-model and how to submit using jquery?如何使用 AngularJS 的 ng-model 创建一个数组以及如何使用 jquery 提交?
【发布时间】:2017-07-24 15:17:35
【问题描述】:

我必须使用 jquery 和 angularjs 提交值数组。当我单击提交按钮时,我只得到第一个数组值。如何使用 ng-model 获取所有数组值。这是我的所有代码 https://jsfiddle.net/rijo/6dLxhr7j/ 下面给出的脚本代码

$scope.onSubmit = function(){
    sum = $scope.obj;
    console.log(sum);
        $http({
            method : 'POST',
            url : 'admin_controller.php',
            data: $.param(sum),
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        }).then(function (response) {
            console.log("OK");
        });
    }

请任何人帮忙..谢谢!

【问题讨论】:

标签: javascript php jquery angularjs arrays


【解决方案1】:

您必须将数据作为对象发布,将数组作为对象属性值传递。在这种情况下,我使用的是$http.post 快捷方式。

function buildParam(){
    // write any needed logic to get, build your array
    // maybe a loop extracting values from collection, etc.
    var myArray = []; // here your array of values, objects, etc.
    return myArray;
}

$scope.onSubmit = function(){
    sum = {
        myAttr: buildParam()
    };

    $http.post('admin_controller.php', sum).then(
        function(response) {
            console.log('ok');
        }       
    );
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-12-16
  • 1970-01-01
  • 2016-04-20
  • 1970-01-01
  • 2014-08-24
  • 1970-01-01
  • 2017-06-15
  • 1970-01-01
相关资源
最近更新 更多