看这篇之前建议大家去看看前面两篇文章:
现在来看一下具体的内容,在index.jsp的<script>里面写:
$.ajax({
url:"doindex.jsp",
data:"email="+$("#email").val(),
dataType:"text",
timeout:1000,
beforeSend:function(){
alert('正在验证,请稍后......');
},
success:function(data){
var data = $.parseJSON(data);
$("#semail").html(data.msg);
},
complete:function(){
alert('验证完成!');
},
error: function() {
alert("ajax执行失败");
}
});
然后再写doindex.jsp里面的内容:
String email = request.getParameter("email");
if("2451999120@qq.com".equals(email)){
out.print("{"flag":true,"msg":"<font color='red'>该邮箱已注册!</font>"}");
}else{
out.print("{"flag":false,"msg":"<font color='green'>可以使用!</font>"}");
}