首页 > 开发 > AJAX > 正文

Ajax实现异步刷新验证用户名是否已存在的具体方法

2024-09-01 08:30:06
字体:
来源:转载
供稿:网友

都是简单的实例,所以直接发代码

静态页面Ajax.html

代码如下:
<html>
    <head>
        <title>Ajax</title>
        <script type="text/javascript">
            function loadXMLDoc() {
                if (document.getElementById("account").value == "") {
                    document.getElementById("accDiv").innerHTML = "用户名不能为空";
                    return;
                }
                var xmlHttp;
                if(window.XMLHttpRequest) { // code for IE7+
                    xmlHttp = new XMLHttpRequest();
                }
                else { // code for IE5/IE6
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }

                xmlHttp.onreadystatechange = function () {
                    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                        //document.getElementById("myDiv").innerHTML=xmlHttp.responseText;
                        if (xmlHttp.responseText == "true") {
                            document.getElementById("accDiv").innerHTML = "用户名不可用";
                        }
                        else {

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表