var xhr;//声明全局变量 用来表示XMLHttpRequest对象
//验证码的 验证
function validateCodeCheck(){
xhr = createXhr(); //1.创建XmlHttpRequest对象
var vc = document.getElementById("validate_code").value;
var u=trim(vc);
if(u==""){
document.getElementById("message_vc").innerHTML =
"<strong><font face='楷体' size='3' color='red'>请输入验证码</font></strong>";
document.getElementById("message_vc").focus();
return;
}
var _vc = encodeURI(encodeURI(u));
var myUrl = "<%=request.getContextPath()%>/CheckCreateMaServlet?vc=" + _vc;
//xhr.open("get","CheckIdServlet?id="+_userId+"&now="+mydate,true);
xhr.open("get", convertUrl(myUrl), true); //2.调用open()方法打开一个新的请求
xhr.send(); //3.调用send()方法发送请求到服务器端
xhr.onreadystatechange = myCreateMaCheck; //4.编写用于处理 readyState 属性值发生改变的方
}
function myCreateMaCheck() {
if (xhr.readyState == 4 && xhr.status == 200) { //当readyState的属性为值 为4时表示HTTP 响应已经完全接收
var returnData = xhr.responseText; //当前请求的http状态码值200时表示成功
//alert(returnData); //这是双重保险
if(returnData=="no"){
document.getElementById("validate_code").value="";
document.getElementById("validate_code").focus();
document.getElementById("message_vc").innerHTML =
"<strong><font face='楷体' size='3' color='red'>验证码有误</font></strong>";
}else{
document.getElementById("message_vc").innerHTML =
"<strong><font face='楷体' size='3' color='green'></font></strong>";
}
}
}
</script>
<body>
<li>
<label class="lable-t">验证码:</label>
<input type="text" name="validate_code" id="validate_code" size="10"
maxlength="4" style="height:25px; vertical-align:middle"
value="" onblur="validateCodeCheck();"/>
<label id="message_vc"></label>
<img id="idenimage" src="createMa.jsp" alt="" />
<a href="#" onclick="idenfunc();" class="blue">看不清</a>
</li>
</body>