Fat-Free Framework & Abide AJAX 表单提交无效

Fat-Free Framework & Abide AJAX form submission not working

我在网站注册时使用 Foundation 5.5.3 和 Abide 表单验证。所以我的 Javascript 看起来像这样:

$('form#register').on('valid.fndtn.abide', function() {
  var data = {
        'email'     : $('#email').val(),
        'username'  : $('#username').val(),
        'password'  : $('#password').val()
      };

  $.ajax({
    method: 'POST',
    url: 'user',
    data: $('#email, #username, #password').serialize(),
    beforeSend: function() {
      console.log(data);
    }
  });
});

我在此处跳过添加 HTML,因为我可以从 console.log 中看到 data 对象中显示的数据。我试过禁用 async 并添加 headers: {'Content-Type': 'application/x-www-form-urlencoded'} 但都没有用。

然后在 F3 中,我有以下内容:

$f3->map('/user', 'User');

class User {
  private $email;
  private $username;
  private $password;

  function get() { }

  function post($f3) {
    global $handler; // This is a PHPConsole handler instance for debugging

    $email = $f3->get('PARAMS.email');
    $username = $f3->get('PARAMS.username');
    $password = $f3->get('PARAMS.password');

    $handler->debug($email, 'email:');
    $handler->debug($username, 'username:');
    $handler->debug($password, 'password:');
  }

  function put() {

  }

  function delete() {

  }
}

$email$usernamepassword 的调试输出始终是来自 PHPConsole 的 null。我错过了什么?

你做错了

$email = $f3->get('PARAMS.email');
$username = $f3->get('PARAMS.username');
$password = $f3->get('PARAMS.password');

应该是

$email = $f3->get('POST.email');
$username = $f3->get('POST.username');
$password = $f3->get('POST.password');

F3存储$f3->get('GET');中的Get数据,$f3->get('POST.email');中的post数据 等等