所以我坚持制作一个2拼接的注册表单,现在我遇到了这个ajax请求,我必须检查字段是否填写正确(电子邮件和名称),然后才能继续到表单的其他部分。< / p>
我对ajax请求非常新,我非常了解并且已经尝试过自己的工作,继续我所做的事情:
的index.php:
<input name="full_name" type="text" id="full_name" class="required">
Email:
<input name="usr_email" type="text" id="usr_email3" class="required email">
</td>
</tr>
<script>
$("#continue").click(function () {
$.ajax({
type: "POST",
url: "dbc.php?check=First",
data: "full_name&usr_email",
success: function(msg){
alert($err);
}
});
$("#First_1").hide();
$("#Next_2").toggle();
return false;
});
</script>
现在我希望First_1隐藏,Next_2要切换,如果它已成功控制(如果请求输出为1),则用$ err警告.. 这是dbc.php?check = First
if(isset($_POST['check']) AND $_POST['check'] == 'First') {
if(empty($_POST['full_name']) || strlen($_POST['full_name']) < 4)
{
$err[] = "FEL - Vänligen ange fullständiga namn. Please enter atleast 3 or more characters for your name";
}
if(!isEmail($_POST['usr_email'])) {
$err[] = "FEL - Invalid email address.";
}
if(empty($err)){
echo 1;
}
}
我怎样才能使这项工作,我不认为数据:在ajax请求中是正确的..
更新: 表格:
form action="index.php?page=checkin" method="post" name="regForm">
<div id="First_1">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<table cellpadding="0" cellspacing="5">
<tr>
<td style="padding: 5px;">
Fullständiga namn:
</td>
<td>
<input name="full_name" type="text" id="full_name" class="required">
</td>
</tr>
<tr>
<td style="padding: 5px;">
Email:
</td>
<td>
<input name="usr_email" type="text" id="usr_email" class="required email">
</td>
</tr>
<tr>
<td style="padding: 5px;">
Sex:
</td>
<td><select name="sex"><option value="male">Kille</option><option value="female">Tjej</option></select>
</td>
</tr>
<td> <td>
<input type="submit" id="continue" value="Fortsätt">
</td></td>
</table>
</td>
</tr>
</table>
</div>
<script>
$("#continue").click(function () {
$.ajax({
type: "POST",
url: "dbc.php?check=First",
data: {full_name : $('#full_name').val()
usr_email : $('#usr_email').val()},
success: function(msg){
if(msg==1){
$("#First_1").hide();
$("#Next_2").toggle();
}else{
alert(msg)
}
}
});
return false;
});
</script>
<div id="Next_2" style="display: none">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<table cellpadding="0" cellspacing="5">
<tr>
<td style="padding: 5px;">
Lösenord:
</td>
<td>
<input name="pwd" type="password" class="required password" id="pwd">
</td>
<td>
En gång till..
</td>
<td>
<input name="pwd2" id="pwd2" class="required password" type="password" >
</td>
<td>
<input name="doRegister" type="submit" id="doRegister" value="Register">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
答案 0 :(得分:1)
<script>
$("#continue").click(function () {
$.ajax({
type: "POST",
url: "dbc.php?check=First",
data: {full_name : $('#full_name').val(),
usr_email : $('#usr_email').val()},
success: function(msg){
if(msg==1){
$("#First_1").hide();
$("#Next_2").toggle();
}else{
alert(msg)
}
}
});
return false;
});