取出用戶名中的值,讓后臺來判斷一下是不是存在,把信息返回給前端,前端顯示,用ajax就可以了:
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供農(nóng)安企業(yè)網(wǎng)站建設,專注與成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設、HTML5、小程序制作等業(yè)務。10年已為農(nóng)安眾多企業(yè)、政府機構(gòu)等服務。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡公司優(yōu)惠進行中。
$('#btn').bind('click',?function(event)?{
//取出你用戶名
var?username?=?$('#username').val();
$.ajax({
url:?'/path/to/file',
dataType:?'json',
data:?{username:?username},
success?:?function(obj){
//obj是返回的信息,說明用戶名是不是存在
//執(zhí)行你想要的操作
}
})
});
jquery調(diào)用ajax,調(diào)用后臺方法判斷用戶名是否重復。驗證的話,varusername=$("#username").val();if(username==""){returnfalse;}上面為驗證不能為空
$('#username').blur(function(){
$.ajax({
url:從數(shù)據(jù)庫驗證用戶是否重復的action地址,
type:'POST',
data:{username:username},
dataType:'json',
success:function(jsonData){
if (jsonData == null) {
$(“#tips”).html('查詢用戶名列表錯誤');
}else if (jsonData.result == "true") {
$(“#tips”).html('用戶名重復');
}else if(jsonData.result == "false") {
$(“#tips”).html('恭喜你,用戶名可以使用');
}
},
error:function(jsonData){
}
});
});