XMLHttpRequest

来源:互联网 发布:游戏美工外包 编辑:程序博客网 时间:2024/05/18 14:15

<input type="text" id="email" name="email" onblur="validateEmail()">

 

 

    <script type="text/javascript">
        var xmlHttp;
        function createXMLHttpRequest() {
            if (window.ActiveXObject) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
            }
        }

        function validateEmail() {
            var email = document.getElementById("email");
            var url = "validate?email=" + escape(email.value);
            xmlHttp.open("GET", url);
            xmlHttp.onreadystatechange = callback;
            xmlHttp.send(null);
        }
        function callback() {
            if (xmlHttp.readyState == 4) {
                if (xmlHttp.status == 200) {
                    //do something
                }
            }
        }
    </script>

原创粉丝点击