javascript和jquery實(shí)現(xiàn)用戶登錄驗(yàn)證
在上一篇文章Ajax實(shí)現(xiàn)異步用戶名驗(yàn)證功能中,用javascript實(shí)現(xiàn)了用戶驗(yàn)證,但并沒有對密碼進(jìn)行驗(yàn)證,這次追加了這個功能,并分別用javascript和jquery實(shí)現(xiàn)。
一.用jquery的ajax實(shí)現(xiàn)的關(guān)鍵代碼
實(shí)現(xiàn)如下
/*jquery實(shí)現(xiàn)
$(document).ready(function(){
$("#account").blur(function(event) {
$.ajax({
type:"GET",
url:"checkAccount.php?account="+$("#account").val(),
dataTypes:"text",
success:function(msg){
$("#accountStatus").html(msg);
},
error:function(jqXHR) {
alert("賬號發(fā)生錯誤!")
},
});
});
$("#password").blur(function(event) {
$.ajax({
type:"GET",
url:"checkPassword.php?",
dataTypes:"text",
data:"account="+$("#account").val()+"&password="+$("#password").val(),
success:function(msg){
$("#passwordStatus").html(msg);
},
error:function(jqXHR) {
alert("密碼查詢發(fā)生錯誤!")
},
});
});
}); */二.用javascript實(shí)現(xiàn)的關(guān)鍵代碼
實(shí)現(xiàn)如下
//javascript實(shí)現(xiàn)
function checkAccount(){
var xmlhttp;
var name = document.getElementById("account").value;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET","checkAccount.php?account="+name,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
document.getElementById("accountStatus").innerHTML=xmlhttp.responseText;
}
}
function checkPassword(){
var xmlhttp;
var name = document.getElementById("account").value;
var pw = document.getElementById("password").value;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET","checkPassword.php?account="+name+"&password="+pw,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
document.getElementById("passwordStatus").innerHTML=xmlhttp.responseText;
}
}mysql和數(shù)據(jù)庫部分跟上篇博文的一樣沒有改變,運(yùn)行結(jié)果如下圖

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。
- jQuery+Ajax用戶登錄功能的實(shí)現(xiàn)
- jquery 彈出登錄窗口實(shí)現(xiàn)代碼
- PHP+jQuery+Ajax實(shí)現(xiàn)用戶登錄與退出
- jquery ajax 登錄驗(yàn)證實(shí)現(xiàn)代碼
- 基于jquery ajax 用戶無刷新登錄方法詳解
- 基于Jquery+div+css實(shí)現(xiàn)彈出登錄窗口(代碼超簡單)
- JQuery記住用戶名密碼實(shí)現(xiàn)下次自動登錄功能
- 使用Jquery打造最佳用戶體驗(yàn)的登錄頁面的實(shí)現(xiàn)代碼
- jQuery實(shí)現(xiàn)彈出窗口中切換登錄與注冊表單
- jQuery實(shí)現(xiàn)簡單登錄條件判斷
相關(guān)文章
通過循環(huán)優(yōu)化 JavaScript 程序
這篇文章主要介紹了通過循環(huán)優(yōu)化 JavaScript 程序,對于提高 JavaScript 程序的性能這個問題,最簡單同時也是很容易被忽視的方法就是學(xué)習(xí)如何正確編寫高性能循環(huán)語句。下面我們來學(xué)習(xí)一下吧2019-06-06
基于JavaScript實(shí)現(xiàn)前端文件的斷點(diǎn)續(xù)傳
這篇文章主要介紹了基于JavaScript實(shí)現(xiàn)前端文件的斷點(diǎn)續(xù)傳的相關(guān)資料,需要的朋友可以參考下2016-10-10
JavaScript中的this指向綁定規(guī)則及常見面試總結(jié)
這篇文章主要為大家介紹了JavaScript中的this指向綁定規(guī)則及箭頭韓碩中的this指向,還b包含了常見面試總結(jié),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12
使用Fuse.js實(shí)現(xiàn)高效的模糊搜索功能
在現(xiàn)代?Web?應(yīng)用程序中,實(shí)現(xiàn)高效的搜索功能是至關(guān)重要的,Fuse.js?是一個強(qiáng)大的?JavaScript?庫,它提供了靈活的模糊搜索和文本匹配功能,使您能夠輕松實(shí)現(xiàn)出色的搜索體驗(yàn),文中代碼示例講解的非常詳細(xì),需要的朋友可以參考下2024-01-01

