0

我试图了解这个功能。但是,每次我运行它时,它都会告诉用户代码不正确,尽管我很难做到。有人可以在这里提出我的缺陷吗

html很简单

<form id="Join_league" method="post" action="<? echo $HTTP_SERVER_VARS['PHP_SELF'];?>">
    <input name="league_code" id="league_code" class="input">
                    <br><br>
    <input id="Join_button" name="Join_button" value="Enter League" type="submit"/>
</form>

这是我的 javascript/ajax 函数

          <script src="http://code.jquery.com/jquery-latest.js"></script>
           <script type="text/javascript" src="http://jzaefferer.github.com/jquery   validation/jquery.validate.js"></script>


    <script type="text/javascript">

      $(document).ready(function() {
$.validator.addMethod("valid_code",function(value,element){
    var parameter="";
    $.ajax({
          url: "check_league_code.php",
          type: "POST",
          async: false,
          data: parameter,

          success:function(output)
                 {
                    return true;
                 }
     });
});


$("#Join_league").validate({
    rules: {
    league_code: {number : true,required : true ,
                              valid_code: true
                                            }
},
messages: {
    league_code: { required:"<strong>Please enter code</strong>",
                  number:"<strong>Please enter number only</strong>",
                valid_code:"<strong>Sorry incorrect code entered</strong>"
        }

}

   })

});

</script>

有什么建议么?

4

1 回答 1

0

这是我用来返回真假的代码

<script type="text/javascript">
$(document).ready(function() {

    jQuery.validator.addMethod("valid_code", function(value,element) {
          var isSuccess = false;
          $.ajax({ url: "check_league_code.php",
          data: "",
          async: false,
          success: function(msg) { 
                      if(msg === "1")
                              {
                                isSuccess=true;
                              }
                    }
           });
                return isSuccess;
             },"<strong>Sorry incorrect code entered</strong>");



    $("#Join_league").validate({
        rules: {
            league_code: {
                required : true,
                number : true,
                valid_code: true
                        },
            messages: {
                league_code: {
                    required: "<strong>Please enter code</strong>",
                    number: "<strong>Please enter number only</strong>",
                    valid_code: "<strong>Sorry incorrect code entered</strong>"
                             }
                     }
        }
    });

});

于 2013-04-22T18:14:32.687 回答