Ajax实现表单验证

<script type="text/javascript">
        var xmlhttp;
        function init(){
            if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }else{// code for IE6, IE5
                  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        function callback(){
            if(xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("tishi").innerHTML=xmlhttp.responseText;
            }
        }
        function yanzheng(){
            var name=document.getElementById("name").value;
            xmlhttp.onreadystatechange=callback;
            xmlhttp.open("GET","yanzheng.action?name="+name,true);
            xmlhttp.send(null);
        }
        window.onload=init;
    </script>
原文地址:https://www.cnblogs.com/yiban/p/ajax_yanzheng.html