jQuery validate + AJAX e-mail availiability check

后端 未结 2 758
渐次进展
渐次进展 2020-12-18 17:00

UPDATED I\'m using jQuery validate plugin and remote method to check email availiability with ajax, but I don\'t understand why ajax calls only once. When e

相关标签:
2条回答
  • 2020-12-18 17:35

    the reason why ajax fires only once is that you have overwritten the success callback of jQuery validate's remote method. Keep it simple and try something like this:

    <input name="email_address"/>
    

    with script

    <script>
    $(function () {
        $('form').validate({
            rules: {
                email_address: {
                    required:true,
                    remote: {
                        url: "your_script.php"
                    }
                }
            },
            debug: true,
            submitHandler: function () { alert('ok'); }
        });
    
    
    });
    </script>
    

    and php like

    <?php 
    
    echo $_GET['email_address'] == "bob";
    
     ?>
    
    0 讨论(0)
  • 2020-12-18 17:42
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
    
        $(document).ready(function(){
    
            $('.checkout-form').validate({
                rules: {
                    on0 : {
                        required : true,
                        remote : {
                            url: YOUR_HOST,
                            type: "post",
                            data: {
                                email_address: function()
                                {
                                    return $("#email_address").val();
                                }
                            }
                        }
                    },
                },
                messages : {
                    required:"message",
                    remote: "message"
                }
            });
        });
    </script>

    in html

    <input type="text" name="on0" value="Your e-mail" class="form-field no-mr check-email" id="email_address"/>

    And in php code

    <?php 
    
    echo $_POST['email_address'];
    
     ?>
    0 讨论(0)
提交回复
热议问题