索引.php:
<form id = "regform" action = "registration.php" method = "POST">
<label id = "namelabel">Username: </label> <input type = "text" name = "username" class = "username" maxlength = "40" placeholder = "Enter a Username"><br>
<label id = "namelabel">Password: </label> <input type = "password" class = "password" name = "password" placeholder = "Enter Password"><br>
<label id = "namelabel">Gender: </label>
<input type="radio" name="gender" value = "Male"> Male
<input type="radio" name="gender" value = "Female"> Female
<label id = "namelabel">Email: </label> <input type = "text" name = "email" class = "email" placeholder = "Enter your Email"><br>
<a href="#" title="Register" id = "register" style = "margin-left:25px;">Register</a>
</form>
$("#register").click(function () {
$.post($('#regform').attr("action"), $('#regform').serializeArray(), function (data) {
if (data == 'checkradio') {
$('#regmsg').html('Please choose a gender.');
}
});
});
服务器端:
$required_fields = array('username','password','gender','email');
foreach($_POST as $key =>$value) {
if(empty($value) && in_array($key, $required_fields) === true){
echo 'checkradio';
}
}
它序列化除单选按钮之外的所有内容。问题是什么?