ajax實(shí)現簡(jiǎn)單登錄頁(yè)面 DATE: 2026-05-04 17:14:11
這篇文章主要為大家詳細??介紹了ajax實(shí)現簡(jiǎn)單登錄頁(yè)面,實(shí)現文中示例代碼介紹的簡(jiǎn)單非常詳細,具有一定的登錄參考價(jià)值,感興趣的頁(yè)面小伙伴們??可以參考一下
本文實(shí)例為大家分享了ajax實(shí)現簡(jiǎn)單登錄頁(yè)面的具體代碼,供大家參考,實(shí)現具體內容如下
一.什么是簡(jiǎn)單ajax
Ajax是一種無(wú)需重新加載整個(gè)網(wǎng)頁(yè)( ?ヮ?),能夠更新部分網(wǎng)頁(yè)的登錄技術(shù)。
二.ajax的頁(yè)面工作原理
Ajax工作原理是一個(gè)頁(yè)面的指定位置可以加載另一個(gè)頁(yè)面所有的輸出內容,這樣就實(shí)現了一個(gè)靜態(tài)頁(yè)面也能獲取到數據庫中的實(shí)現返回數據信息了。 所以Ajax實(shí)現了一個(gè)靜態(tài)網(wǎng)頁(yè)在不刷新整個(gè)頁(yè)面的簡(jiǎn)單情況下與服務(wù)器通信,減少(╬?益?)了用戶(hù)等待時(shí)間,登錄同時(shí)降低了網(wǎng)絡(luò )流(liu)量,頁(yè)面增強了客戶(hù)體驗的實(shí)現友好程度。
三.用ajax實(shí)現簡(jiǎn)單的簡(jiǎn)單登錄頁(yè)面
1.ajax_login.html??
<!DOCTYPE html>
<??;html lang=(′_ゝ`)"en">
<head>
<meta charset='UTF-8'>
<title>??;登錄頁(yè)面</title>
<style>
.di(′?ω?`)v1{
display: non(′▽?zhuān)?)e;
color: red;
}
</style>
<script src='/sta(╬?益?)tic/js/jquery-1.12.4.min.j( ?ヮ?)s'></script>
&l??t;script>
$(function () {
$('#register').click(function () {
// alert('ok');
//獲取用戶(hù)名和密碼:
usernam??e = $('#username').val();
password = $('#password').val();
rember = $('#rember').??v(′?`)al();
// alert(remb?er);
$.ajax({
url:"/login_ajax_che(???)ck",
type:"POST"(′_ゝ`), //提交方式
data:{ "username":username,"password":password,"rember":rember},
dataType:"json"(??ヮ?)?*:???,
}).done(function (data) {
if (data.res==1){
// alert('username')
location.h??reヾ(′ω`)?f="/index" rel="external nofollow"
}else{
// alert('username');
$('.div1').show().html('用戶(hù)名或密碼輸入錯誤')
}
})
});
});
</??script>
</head>
<body>
<div>
用戶(hù)名:<input ty??pe='text' id='username' ><br/>
記住用戶(hù)名:<input type="chec??kbox" id="rember"><br/(′▽?zhuān)?>
密碼<input type="password" id='password'><br/>
<input type=( ?ヮ?)"submit" value="登錄" id="regis(??-)?ter">
<div class="div1"></div>
</div>
</body>
&??lt;/html>
2.views.py
def login_ajax(reques(′ω`)t):
"""ajax登錄頁(yè)面"""
return render(request,"booktest/login_ajax.html")
def login_ajax_check(request):
"""ajax登錄校驗"""
username = request.POST.g?et('username') # 通過(guò)'username'這個(gè)鍵拿到數據
password = request.POST.get('password')
#若登錄正確
if username == "admin" and password == "12":
jsonresponse = JsonResponse({ "res":1})
#登錄錯誤:
else:
return JsonResponse({ "res":0})
以上就是本文的全部?jì)热?,希望對大家的登錄學(xué)習有所幫助,也希望大家多多支持腳本之家。
來(lái)源:腳本之家
鏈接:https://www.jb51.net/article/189008.htm

