This article mainly introduces the example code of Ajax verification user name. It is very practical and very practical ajax technology. It provides the ajax source code. Friends who are not familiar with ajax verification user name can take a look!
The code to verify the username using Ajax is as follows:
get guestbook/index.php m : index a : verifyUserName username : 要验证的用户名
Return :
{ code : 返回的信息代码 0 = 没有错误,1 = 有错误 message : 返回的信息 具体返回信息 }
js Code:
oUsername1.onblur = function() { //失去焦点的时候,把当前用户名给后端去验证 ajax('get', 'guestbook/index.php', 'm=index&a=verifyUserName&username=' + this.value, function(data) { //alert(data); 浏览器调试查看 var d = JSON.parse(data); //解析 oVerifyUserNameMsg.innerHTML = d.message; //将返回信息展示到页面上 if (d.code) { //code : 返回的信息代码 0 = 没有错误,1 = 有错误 oVerifyUserNameMsg.style.color = 'red'; //错误信息加红色 } else { oVerifyUserNameMsg.style.color = 'green'; //正确信息加绿色 } }); }
I will share with you so much about the ajax verification user name example code, I hope it will be helpful to everyone. !
Related recommendations:
Ajax asynchronous file upload example code sharing
Detailed explanation of Ajax request and Filter cooperation case
Ajax quickly solves the problem that the parameter is too long and cannot be submitted successfully
The above is the detailed content of Ajax verification username example code. For more information, please follow other related articles on the PHP Chinese website!