IT猫扑网文章教程

分类分类

ajax验证用户名是否可用

2015-06-28 00:00作者:网管联盟

    Ajax很简单(jsp例子)

    首先是jsp页面和脚本,为了方便写在一个里面

    这是一个很常见的检测用户名是否存在的功能

    这里用的是struts ,可以在路径path中加加上要传的值name 在action中连接数据库 验证是否存在

    --------------------------------------------------------------------------------

    <%@ page contentType=&text/html; charset=GBK& %>

    <html> 

    <head>

    <title>

    ajax

    </title> 

    </head>

    <body bgcolor=&#ffffff&>

    <h1>

    <input name=&username& type=&text& maxlength=&20& />

    <input id=&chk-name-btn& type=&button& value=&检测帐号& onclick=&testName(’<%=request.getContextPath()%>’)& />

    <div id=&view_name&></div>

    </h1>

    </body>

    </html>

    <script language=&javascript&>

if (window.ActiveXObject && !window.XMLHttpRequest) {


     window.XMLHttpRequest=function() {

     return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf(’msie 5’) != -1) ? ’Microsoft.XMLHTTP’ : ’Msxml2.XMLHTTP’);


  };

}//取得XMLHttpRequest对象


    function testName(path){

    //path是取得系统路径

   var view_name=document.getElementById(&view_name&);

     var req=new XMLHttpRequest();

展开全部

相关文章

说两句网友评论
    我要跟贴
    取消