ajax可以传送一个或多个参数到后台php中
<script>
$(function(){
$("#sub_btn").click(function(){
var email = $("#email").val();
var preg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; //匹配Email
if(email=='' || !preg.test(email)){
alert("请填写正确的邮箱!");
}else{
$.ajax({
url:'xxx',
type:'post',
dataType:'json',
data:{'email':email},
success:function(data,status){
alert(data.value);
},
error:function(){
alert('error');
}
});
}
}); $('#submit_btn').click(function(){
var email = $("#email").val();
var key = $("#key").val();
var pwd = $("#pwd").val();
var confirm_pwd = $("#confirm_pwd").val(); var preg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; //匹配Email
var preg_pwd = /^[0-9a-zA-Z]{6,12}$/;
var preg_key = /^[0-9]{6}$/;
if(email=='' || !preg.test(email)){
alert("请填写正确的邮箱!");
return false;
}
if(key=='' || !preg_key.test(key)){
alert('请输入6位数字验证码');
return false;
}
if(pwd=='' || !preg_pwd.test(pwd)){
alert("请填写6到12位由字母和数字组成的密码,区分大小写");
return false;
}
if(confirm_pwd=='' || confirm_pwd != pwd){
alert('请输入正确的确认密码');
return false;
}else{
$.ajax({
url:'xxx',
type:'post',
dataType:'json',
data:{'email':email,'pwd':pwd,'key':key},
success:function(data,status){
alert(data.value);
},
error:function(){
alert('error');
}
}); }
});
})
</script>