我使用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() {
}
}
来自PHPConsole的$email
,$username
和password
的调试输出始终为null
。我错过了什么?
答案 0 :(得分:3)
你做错了
$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');
中获取数据,在$f3->get('POST.email');
中发布数据
等