解决方案 »

  1.   

    下面是个实例 别照抄 只是借鉴一下就好
    function check_login() {
             var code = $("#code").val();
             if(code == "") {
             $("#code_msg").text("请输入验证码.");
             return;
             }
            
             $.post(
             "login.do",
             $("#myform").serialize(),
             function(data) {
                                             //if里面是对调回的数据进行判断 具体的判断条件你可以自己写 这个是我以前项目用的 你不用照抄
              if(data.flag==1) {
             //验证码错误 这里是用ajax将验证码的输入项直接显示错误信息了 你要想用alert 就把这个方法改一下就好
             $("#code_msg").text("验证码错误.");
             change();
             } else {
             //成功
             location.href = "toIndex.do";
             }
             }
             );
             }
      

  2.   

    -----------------------------------------------------------------------------------------------------------------------
    十分感谢  可以在帮我看看我  我下面这段代码  哪里有错呢???  一直调用error的方法
    就连alert(“请输入验证码”)都不显示
    -----------------------------------------------------------------------------------------------------------------------
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'index.jsp' starting page</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <script type="text/javascript" src="<%=path%>/js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript">
    $(function () {  
         $("#Verify").click(function(){
         $(this).attr("src","SecurityCodeImageAction?timestamp="+new Date().getTime());
    });
                 
    });
     $(document).ready(function(){
    $("#button").click(function(){
     var name= $('#id').attr('value');
    if (name!=null||name!=""){
        $.ajax({
    url:"yangzheng",
    type:"post",
    dataType:"json",
    success:function(data){
    if(data.msg!=null){
    $("#notsuccess").html("&nbsp;<br>");
                var html ="成功了" ;
                $('#notsuccess').html(html);
    }else{
      $("#notsuccess").html(data.msg);
                  $("#notsuccess").css("color","red");
    }
    },
    error:function(){
    alert("出现错误");
    }
    });
    }else{
    alert("请填写验证码");}
    });
    });
    </script>
      </head>
      
      <body>
          <form id="ids" action="yanzheng" name="form" method="post">           
                     验证码:<input type="text" id="id" name="name" value="" />
          <img src="SecurityCodeImageAction" id="Verify"  style="cursor:hand;"/><font color="red">看不清?单击验证码</font>
          <br/>
          <div id="notsuccess"></div>
          <input type="button" id="button" name="sbt" value="进入!"/>
          </form>
      </body>
    </html>
      

  3.   


    //有必要写这么麻烦吗?
    var name= $('#id').attr('value');
    直接
    var name = $("#id").val();
    不就行了
    并且id是关键字啊换个id名称
    url:"yangzheng",
    这个url确定是这样?
      

  4.   

    并且像这种js错误
    直接用调试工具跟踪
    firebug或者ie8以及以上都会有js调试工具,直接就能定位哪行的错误