首页 > 代码库 > PHP (20140516)

PHP (20140516)

用Ajax验证验证码:

 1 var xmlHttp;
 2 function getXmlHttp(){
 3     if(window.ActiveXObject){
 4         xmlHttp = new ActiveXObject("MICROSOFT.XMLHTTP");
 5     }else if(window.XMLHttpRequest){
 6         xmlHttp = new XMLHttpRequest();
 7     }
 8 }
 9 
10 function checkYZM(){
11 
12 
13     getXmlHttp();
14     var  f = false;
15     xmlHttp.open("GET","checkYZM.php?yzm="+yzm.value,false);
16     xmlHttp.onreadystatechange = function(){
17         if(xmlHttp.readyState == 4){
18             if(xmlHttp.status == 200){
19                 var str = parseInt(xmlHttp.responseText);
20                 if(str){
21                     yzmCheck.innerHTML = "验证成功!";
22                     f = true;
23                 }else{
24                     yzmCheck.innerHTML = "验证失败!";
25                     f = false;
26                 }
27             }
28         }
29     }
30     xmlHttp.send(null);
31     return f;
32 
33 }