提交两次的Angular表单

时间:2016-07-02 14:57:45

标签: angularjs

我有一个表单,它将数据发送到数据库,但它会两次。

这是控制器的代码和html视图的示例。



        $scope.addEvent = function(type) {
            if (!$scope.sentAdd) {
            $scope.newEvent.admission = type;
            $scope.newEvent.customer_id = $scope.curUID;
            console.log($scope.newEvent);
            $http({
              url: '/addEvent',
              method: "POST",
              data: $.param($scope.newEvent),
              headers: {
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
              }
            })
            .success(function(data){
                    //console.log(data);
                    $scope.newEvent = $scope.cleanEvent;
                    $scope.addEventForm.$setPristine();
                    $scope.sentType = type;
                    $scope.sentAdd = true;
                    $.fancybox.close();
                    $.fancybox.open({ href: '#eventSuccess', type: 'inline' });
            });
            } 
        };

<form name="addEventForm" novalidate>
  <input type="text" ng-model="text">
  <a ng-click="addEvent('Paid')">Add Paid Event</a><br>
  <a ng-click="addEvent('Free')">Add Free Event</a>
</form>
&#13;
&#13;
&#13;

0 个答案:

没有答案