解决方案 »

  1.   

    function processData(data){
        if(data=='exist'){
            $('#accounthint').html('<p>该账号已经存在</p>');
        }
        else $(this).html('<p>该账号可以使用</p>');
    }
      

  2.   


    加上了以后还是没有反应T  T
    在action里面加上一个输出语句,也没有被执行。为什么没有进到action呢?
      

  3.   

    后台没进去,先确认你的action 和xml 配置文件是否匹配。
      

  4.   


    加上了还是不行 T T后台方法前面有加[HttpGet]么
      

  5.   

    额。有几处我看上去不太对。但是我也不知道我对不对..
    1、$.get()中的第一个参数URL,不知道是你那么设置的还是我没接触到,我用的SpringMVC,Struts2都快忘了,action有那么长吗=、=,要是我直接就CheckAccountName.action
    2、URL后边应该没有“?”吧,如果用问号,可以就
    $.get('src/struts/action/CheckAccountName.action?userid = '+ account,了第二个参数就省了
    3、第三个参数,我没这么写过,一般都是function(data) {},如果你拆开写的话,调用这个JS后边应该加括号吧?processData(data);
    如果还没用的话,用火狐浏览器FireBug追一下吧 应该会有错误,看看到底是哪出毛病了
      

  6.   

    说错了,我的action也分层,但是没用src/这么分
      

  7.   


    加上了还是不行 T T后台方法前面有加[HttpGet]么没有求解释怎么写。。
    另外,那返回的时候也需要http write这样的函数吗?
      

  8.   

    说错了,我的action也分层,但是没用src/这么分这个应该是直接用就可以,会到struts.xml里面找,我觉得我是没有写httpget造成的。
      

  9.   

    说错了,我的action也分层,但是没用src/这么分这个应该是直接用就可以,会到struts.xml里面找,我觉得我是没有写httpget造成的。
    嗯 还是建议先Firebug看一下,排除一下是否是JS的问题
      

  10.   


    加上了还是不行 T T后台方法前面有加[HttpGet]么没有求解释怎么写。。
    另外,那返回的时候也需要http write这样的函数吗?
    1、就在方法前面加一个  [HttpGet]  这个表示GET方式访问的方法,记得默认的是post样
    2、直接返回值就可以了
      

  11.   

       function clear(){
            document.getElementById("accounthint").innerHTML = "";
        }
        
        function verify(){
        var newXHR;
        createXmlHttp();
        var userid = document.getElementById('accountname').value;
        if(userid=='') document.getElementById('accounthint').innerHTML="用户名不能为空";
        newXHR.onreadystatechange = responseTo;
        newXHR.open('GET','CheckAccountName_check?userid=' + userid,true);
        newXHR.send(null);
        window.alert(newXHR.responseText);
        }
        
        function createXmlHttp(){
    if(window.XMLHttpRequest){
    newXHR = new XMLHttpRequest();
    }else{
        newXHR = new ActiveXObject("Microsoft.XMLHttp");
    }
        }
        function responseTo(){
            if (newXHR.readyState==4){
                var response = newXHR.responseText;
                if(response=="exist")
                    document.getElementById("accounthint").innerHTML = "用户名已经存在";
                else{
                    document.getElementById("accounthint").innerHTML = "恭喜您,可以使用";
                }
        }
    }
    <td width="13%" height="38" class="top_hui_text"><span class="login_txt">帐号:&nbsp;&nbsp; </span>                                           </td>
                                <td height="38" colspan="2" class="top_hui_text"><input name="account.userid" id="accountname"  
                                                                                        onblur="verify()" onfocus="clear()" class="editbox4" value="" size="20">    public String check() throws IOException{
            HttpServletResponse response = ServletActionContext.getResponse();
            response.setContentType("text/html;charset=UTF-8");  
            response.setHeader("Charset","UTF-8"); 
            try{
             PrintWriter out = response.getWriter();
             out.print("exist");
             System.out.println("it is here");
             out.flush();
             out.close();
             //result = am.checkAccountName(this.userid);
            }catch (IOException e){
             e.printStackTrace();
            }
            return null;
        } 
    这是现在的三段代码,但是界面上只能反映为空的情况,还是不能比较是不是存在,
    我已经把action拿出来了,直接返回一个存在,但是还是没反应,为什么啊?
      

  12.   

    已经没有用jquery了,直接ajax了,为什么还是不行呢
      

  13.   

    $.get('src/struts/action/CheckAccountName.action?','userid = '+ account,processData);
    你这都都错了把action?后面的','去掉
      

  14.   

    改成直接ajax后,你确认你的后台方法进去没啊,debug 看看啊/
      

  15.   

    问题已经解决了,是我把callback函数写到建立连接前面了脑抽了
    谢谢了。。