jquery Validation Plugin Validation plugin remote validation issues

Source: Internet
Author: User
Tags php server
With jquery's validation plugin validation plugin, the document says the server needs to return a JSON string, true for valid, "false", undefined, and null for invalid.
Need to verify that the user name has been registered, if it has been registered, return FALSE, if not registered, returns TRUE. The PHP server (Laravel framework) is written like this:

    public function verifyName(Request $request)    {        $username = $request->input('name', '');        $user = User::where('name', $username)->first();        if ($username == $user->name) {            return json_encode(false);        }else{            return json_encode(true);        }    }

The front-end JS code is this:

Problem:
When return false, can return normally, want to return true return, appear trying to get the property of Non-object, do not know what reason.

Reply content:

With jquery's validation plugin validation plugin, the document says the server needs to return a JSON string, true for valid, "false", undefined, and null for invalid.
Need to verify that the user name has been registered, if it has been registered, return FALSE, if not registered, returns TRUE. The PHP server (Laravel framework) is written like this:

    public function verifyName(Request $request)    {        $username = $request->input('name', '');        $user = User::where('name', $username)->first();        if ($username == $user->name) {            return json_encode(false);        }else{            return json_encode(true);        }    }

The front-end JS code is this:

Problem:
When return false, can return normally, want to return true return, appear trying to get the property of Non-object, do not know what reason.

Does your front-end code forget the post data to the backstage?
data:{

name:function(){    return $("input[name='name']").val();}

}

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.