Home  >  Article  >  Backend Development  >  注册页面Ajax检查用户名重复,该如何解决

注册页面Ajax检查用户名重复,该如何解决

WBOY
WBOYOriginal
2016-06-13 13:48:171181browse

注册页面Ajax检查用户名重复
注册页面Ajax检查用户名重复

IE现在60行报错:'null'为空或不是对象

上代码:

HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->    <script type="text/javascript">
        var xmlHttp;
        function createXMLHTTP()
        {
            if(window.ActiveXObject)
            {
                var browseVersion=["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
                for(var i=0;i<browseVersion.length;i++)
                {
                    xmlHttp=new ActiveXObject(browseVersion[i]);
                }   
            }
            else if(window.XMLHttpRequest)
            {
                xmlHttp=new XMLHttpRequest();
            }
            if (!xmlHttp)
            {
                window.alert("不能创建XMLHttpRequest对象实例!");
                return false;
            }
        }
        function $(id)
        {
            return document.getElementById(id);
        }
        function CheckUserName(obj,Msg)
        {
       
            if(obj.value=="")
            {
                alert( "请输入用户名!")
            }
            else
            { 
                createXMLHTTP();
                var url="chkuser.php?name=" + encodeURIComponent(obj.value);
                xmlHttp.open("GET",url,true);
                xmlHttp.onreadystatechange=IsExistUserName;
                xmlHttp.send(null);
            }
        }
        function IsExistUserName()
        {
            if(xmlHttp.readyState == 4)  /*这是60行*/
            {
                var isValid = xmlHttp.responseText;
                var exsits = document.getElementById("exsits"); 
                exsits.innerHTML = isValid.substring(0,4);
            } 
         }
    </script>    
增加新用户
用户名: *
密码: *
重复密码: *


这是chkuser.php页面代码:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php include('chek.php');
include('../config.php');
$name = $_GET[name];
$sql="SELECT * FROM wyx_user WHERE wyx_name='$name'";
$sql=@mysql_query($sql)
if($rs=mysql_fetch_array($sql))
{
    echo "用户名已存在";
}
else
{
    echo "可以注册";
}

?>


------解决方案--------------------
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn