AJAX live checking availability with submit button

后端 未结 1 1266
时光说笑
时光说笑 2021-01-15 15:49
  • test1.php

    
    
    
    
    
            
相关标签:
1条回答
  • 2021-01-15 16:50

    Instead of using a click handler for the button, use the form submit event.

    $(document).ready(function () {
        $('#username').change(function () {
            var userName = $('#username').val();
    
            $.post("getUserName.php", {
                userName: userName
            }, function (data) {
                $("#userNameCheck").html(data);
            });
        });
    
        $('#addform').submit(function () {
            //if the text is `You can use it` allow the form submit else block it
            return $("#userNameCheck").html().trim() == 'You can use it';
        });
    });
    

    Also make sure that you do the same validation in test2.php because, the client side validation can be side stepped.

    0 讨论(0)
提交回复
热议问题