Angularjs如何将复选复选框的值发送到.php?

时间:2015-07-09 12:28:30

标签: javascript php mysql angularjs

我希望仅在选中时才保存多个复选框中包含的值。他们将使用php保存到MySQL数据库中。这是我的HTML代码。

<div class="panel" ng-controller="checkBoxController"> 
    <input class="form-control" placeholder="Cherchez vos contacts" type="text" ng-model="searchText">
    </br>
    <div ng-repeat="employee in employees | filter:searchText ">
        <label class="action-checkbox">
            <input id="{{employee.name}}" type="checkbox" value="{{employee.name}}" ng-checked="selection.indexOf(employee.name) > -1" ng-click="toggleSelection(employee.name)">
        </label>
        <label for="{{employee.name}}"></label>
            {{employee.name}}
        </label>
    </div>
    </br>
    <span class="selected-item">Destinataires choisis:<span>
    <div ng-repeat="name in selection" class="selected-item">
        {{name}}
    </div>
</div>

这是我的JS代码。

var myApp = angular.module('myApp', []);

myApp.controller('checkBoxController', function($scope, $http) {
    $http.get("information.php")
        .success(function (response) {
            $scope.employees = response.records;
        }); 

    $scope.selection = [];

    // toggle selection for a given employee by name
    $scope.toggleSelection = function toggleSelection(employeeName) {
        var idx = $scope.selection.indexOf(employeeName);

        if (idx > -1) {
            $scope.selection.splice(idx, 1);
        } else {
            $scope.selection.push(employeeName);
        }
    };
});

下一步是什么?也许保存在JSON文件中并通过HTTP发送?我迷路了。

1 个答案:

答案 0 :(得分:2)

您所要做的就是拥有一个可以接受JSON的端点,并通过控制器中的函数将数组发送给它。

ClassNotFound: GroovyObject

然后有一个按钮在HTML中发送它:

ClassNotFoundException

让PHP文件接收并处理JSON数组是另一回事。