jQuery Validate remote method usage to check if username already exists

前端 未结 2 1338
花落未央
花落未央 2020-11-22 02:41

I want to validate if username exists in database using jQuery.validate so here\'s what I have so far:

jQuery:

    $(\"#signupForm\").validate({
             


        
相关标签:
2条回答
  • 2020-11-22 03:10

    I've managed to get this to work by changing the PHP technique I was using, here's my PHP:

    <?php
    require_once "./source/includes/data.php";
    header('Content-type: application/json');
    $request = $_REQUEST['username'];
    
    $query = mysql_query("SELECT * FROM mmh_user_info WHERE username ='$username'");
    $result = mysql_num_rows($query);
    if ($result == 0){
    $valid = 'true';}
    else{
    $valid = 'false';
    }
    echo $valid;
    ?>
    

    Thanks everyone here for your help :)

    0 讨论(0)
  • 2020-11-22 03:10

    I have two resources for to look at.

    Official example from the validate plugin: http://jquery.bassistance.de/validate/demo/milk/

    jQuery forum solution: http://forum.jquery.com/topic/jquery-validation-plugin-remote-validation-problem-locks-up

    The possible solution is that the response does not need to be json encoded as far as I can tell. Since json needs key value pairs, suppling just the value won't work. So try to just echo it out as 'true' or 'false' strings.

    Second, the validate uses GET for the form submission method, not POST.

    NOTE: JUST FOUND POSSIBLE SOLUTION QUESTION jQuery Remote validation

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