Detailed explanation of ajax implementation of simple login page

coldplay.xixi
Release: 2020-08-19 10:06:04
forward
2231 people have browsed it

Detailed explanation of ajax implementation of simple login page

The example in this article shares the specific code for ajax to implement a simple login page for your reference. The specific content is as follows

[Related article recommendations:ajax video Tutorial

1. What is ajax

Ajax is a technology that can update part of a web page without reloading the entire web page.

2. The working principle of ajax

The working principle of Ajax is that the specified location of one page can load all the output content of another page, thus realizing a static page You can also get the returned data information from the database. Therefore, Ajax implements a static web page to communicate with the server without refreshing the entire page, reducing user waiting time, reducing network traffic, and enhancing the friendliness of the customer experience.

3. Use ajax to implement a simple login page

1.ajax_login.html

    登录页面    

用户名:
记住用户名:
密码

Copy after login

2.views.py

from django.http import HttpResponse,JsonResponse def login_ajax(request): """ajax登录页面""" return render(request,"booktest/login_ajax.html") def login_ajax_check(request): """ajax登录校验""" username = request.POST.get('username') # 通过'username'这个键拿到数据 password = request.POST.get('password') #若登录正确 if username == "admin" and password == "12": jsonresponse = JsonResponse({"res":1}) return jsonresponse #登录错误: else: return JsonResponse({"res":0})
Copy after login

Related learning recommendations:js video tutorial

The above is the detailed content of Detailed explanation of ajax implementation of simple login page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!