Whether the backend user name exists validation | Show based Ajax when Mouse loses focus | Django Development

Source: Internet
Author: User

2. In the user name location, the mouse leaves the lost focus, uses AJAX to detect whether the user name exists, and displays2.1find the JS file of the checksum front-end input function check_user_name () {var len= $('#user_name'). val (). length; if(len<5| | Len>20)            {                $('#user_name'). Next (). HTML ('Please enter a 5-20-character user name')                $('#user_name'). Next (). Show (); Error_name=true; }            Else            {                //after the verification of the front-end format is successful, add a mouse to lose focus, to determine whether the user name exists;//through the AJAX request view, Jsonresponse returns the judgment result;Ajax Get Methods 3 parameters: 1. Access view; 2. Parameters to be carried by the request; 3. Success execution function after successful;//parameters in the execution function: data is the dictionary returned by the view Jsonresponse; $.get ('/users/check_useranme/', {'username': $('#user_name'). Val ()}, function (data) {//Displays the judging information according to the Returned judgment information .if(Data.ret = = 1){                        $('#user_name'). Next (). HTML ('User name exists'). Show (); Error_name=true; }                    Else{                        $('#user_name'). Next (). Hide (); Error_name=false;            }                }); }    2.2view functions for validationdefCheck_username (Request):#If the user existsUsername = post.get (Request,'username')            ifModels. User.objects.get (user_name=username):returnJsonresponse ({'ret': 1})            Else:                returnJsonresponse ({'ret': 0})

Whether the backend user name exists validation | Show based Ajax when Mouse loses focus | Django Development

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.