1

我有一个 angular-ui 模态,由以下控制器控制:

var emailModal = angular.module('myApp.emailModal', ['ui.bootstrap', 'ui.bootstrap.tpls']);

emailModal.controller('ModalCtrl', ['$scope', '$uibModal', function ($scope, $uibModal) {

  $scope.open = function () {
    var modalInstance = $uibModal.open({
      templateUrl: 'components/emailModal/emailModalView.html',
      backdrop: true,
      controller: 'modalInstanceCtrl'
    });
  }
}]);

emailModal.controller('modalInstanceCtrl', function ($scope, $uibModalInstance, $http) {
  //create blank object to handle form data.
  $scope.user = {};
  //calling our submit function.
  $scope.submitForm = function() {
    //posting data to php file
    $http({
      method: 'POST',
      url: 'components/emailModal/emailInsert.php',
      data: $scope.user, //forms user object
      headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    })
        .success(function(data) {
          if (data.errors) {
            //showing errors.
            $scope.errorEmail = data.errors.email;
          } else {
            $scope.message = data.message;
          }
        });
  };
});

这是实际的模态视图:

<form name="userForm" ng-submit="submitForm()">
<div class="modal-header">
    <h3 class="modal-title">Register</h3>
</div>
<div class="modal-body">
    <div class="form-group">
        <label>E-Mail Address</label>
        <input type="email" name="email" class="form-control" ng-model="user.email" placeholder="Email address" />
        <span ng-show="errorEmail">{{errorEmail}}</span>
    </div>
</div>
<div class="modal-footer">
    <button type="submit" class="btn btn-default">Submit</button>
</div>
</form>

模态加载没有问题,但是一旦点击提交,什么也没有发生。我在控制台中一次没有错误。我究竟做错了什么?这也是我的 PHP 文件:

$errors = array();
$data = array();
// Getting posted data and decodeing json
$_POST = json_decode(file_get_contents('php://input'), true);

// checking for blank values.

if (empty($_POST['email']))
    $errors['email'] = 'E-Mail erforderlich.';

if (!empty($errors)) {
    $data['errors']  = $errors;
} else {
    $data['message'] = 'The data should now be inserted into database!';
}
// response back.
echo json_encode($data);
?>

编辑 1。

该事件在开发工具 - 网络中触发。

这就是我得到的:

请求地址:http://localhost:63342/url-to/emailInsert.php 请求方式:POST 远程地址:127.0.0.1:63342 状态码:200 OK 版本HTTP/1.1

提交时页面没有重新加载,开发工具 - 控制台中没有错误。即使电子邮件尚未插入输入,它也会提供 OK 状态,因此它应该打印一个错误,但它不会这样做。

任何帮助是极大的赞赏。

4

0 回答 0