Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 将数据从Angular UI引导模式窗口发布到PHP_Mysql_Angularjs_Twitter Bootstrap_Angular Ui Modal - Fatal编程技术网

Mysql 将数据从Angular UI引导模式窗口发布到PHP

Mysql 将数据从Angular UI引导模式窗口发布到PHP,mysql,angularjs,twitter-bootstrap,angular-ui-modal,Mysql,Angularjs,Twitter Bootstrap,Angular Ui Modal,我有一个角度ui模式,由以下控制器控制: var emailModal = angular.module('myApp.emailModal', ['ui.bootstrap', 'ui.bootstrap.tpls']); emailModal.controller('ModalCtrl', ['$scope', '$uibModal', function ($scope, $uibModal) { $scope.open = function () { var modalIn

我有一个角度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>
编辑1

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

这就是我得到的:

请求URL: 申请方式:邮寄 远程地址:127.0.0.1:63342 状态代码:200 OK 版本HTTP/1.1

提交时没有重新加载页面,在Dev Tools-Console中没有任何错误。即使电子邮件尚未插入到输入中,它也会给出一个OK状态,因此它应该打印一个错误,但它不会这样做


非常感谢您的帮助。

除了“什么都没发生”之外,您还需要更多的反馈。是否发出请求…如果是,开发工具网络中的状态如何?
submitForm()
是否正在启动?页面正在重新加载吗。。。提供尽可能多的疑难解答信息,并添加错误处理程序。。。这种情况下你需要它,更不用说正常的交通流了。我刚刚编辑了我以前的帖子。感谢您的帮助。您需要元素的验证规则,以避免将其发送为空。至于200。。。这比什么都没发生的进步了一大步。在网络中的这些请求中,还可以确切地看到响应体中返回的内容。如果json未被解析为传递给
数据,则应在php中设置内容类型头,或在$http中设置数据类型头。在调试php时,有时从服务器发回额外数据也很有用。例如,为了确保某些条件有效,请在dev tools网络中真正熟悉该请求中的内容…可以准确地看到发送的内容。我看不出消息会传到哪里去。也不知道modal是否关闭。如果您需要从模态控制器传回数据,则需要遵循docs示例,在
close()
中传回数据,并在
result
中接收数据,并在其他控制器中承诺更多的反馈,而不仅仅是“什么都没有发生”。是否发出请求…如果是,开发工具网络中的状态如何?
submitForm()
是否正在启动?页面正在重新加载吗。。。提供尽可能多的疑难解答信息,并添加错误处理程序。。。这种情况下你需要它,更不用说正常的交通流了。我刚刚编辑了我以前的帖子。感谢您的帮助。您需要元素的验证规则,以避免将其发送为空。至于200。。。这比什么都没发生的进步了一大步。在网络中的这些请求中,还可以确切地看到响应体中返回的内容。如果json未被解析为传递给
数据,则应在php中设置内容类型头,或在$http中设置数据类型头。在调试php时,有时从服务器发回额外数据也很有用。例如,为了确保某些条件有效,请在dev tools网络中真正熟悉该请求中的内容…可以准确地看到发送的内容。我看不出消息会传到哪里去。也不知道modal是否关闭。如果您需要从模态控制器传回数据,则需要按照docs示例,在
close()
中传回数据,并在其他控制器中的
result
promise中接收数据
$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);
?>