求助!!!利用Ajax技术实现一个页面不刷新的,并且验证一个用户名是否被注册过的过程。如果可以注册或者不可以注册,通过脚本向客户端输出一段话。我尝试了很多种方法,但是默认输出的都是在网页最上面,我想把他放在文本框后面,请大侠们帮帮忙。。下面是我写的代码。
<script type ="text/javascript">
    var xmlhttp;       function Validation()       {
            xmlhttp =new ActiveXObject ("Microsoft.XMLHTTP");
            var name=document .getElementById ("Text1");
            xmlhttp.open("Post","YanZheng.aspx?name="+name.value);
            xmlhttp .onreadystatechange=OnMessageBack;
            xmlhttp .send(null);        }
    
   function OnMessageBack()       {
            if (xmlhttp .readystate==4&&xmlhttp .status==200)            {
                document.writeln(xmlhttp .responsetext); 
            }
        }
</script>
        <table>
            <tr>
                <td> 用户名:</td>
                <td><input id="UserName" type="text" onblur="Validation()"/></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input id="PassWord" type="" /></td>
            </tr>
            <tr>
                <td><input id="Submit" type="button" value="注册"/></td>
            </tr>
        </table>

解决方案 »

  1.   


    <script type ="text/javascript"> 
        var xmlhttp; 
          function Validation() 
          { 
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
                var name = document.getElementById("UserName"); 
                xmlhttp.open("GET","YanZheng.aspx?name="+escape(name.value) + "&" + escape(new Date()) , true);
                xmlhttp.onreadystatechange=OnMessageBack; 
                xmlhttp.send(null); 
            } 
        
      function OnMessageBack() 
      {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) 
            { 
                document.getElementById("pad").innerHTML = xmlhttp.responseText; 
            } 
       } 
    </script>         <table> 
                <tr> 
                    <td> 用户名: </td> 
                    <td> <input id="UserName" type="text" onblur="Validation()"/><span id="pad"></span></td> 
                </tr> 
                <tr> 
                    <td>密码: </td> 
                    <td> <input id="PassWord" type="" /> </td> 
                </tr> 
                <tr> 
                    <td> <input id="Submit" type="button" value="注册"/> </td> 
                </tr> 
            </table> 
     
     
      

  2.   

    1楼的方法可以,也是普通的方法...我再稍微补充一下...把SPAN的颜色改成红色方便识别。