Home > Web Front-end > JS Tutorial > Ajax verification username example code

Ajax verification username example code

韦小宝
Release: 2018-01-10 09:59:19
Original
1397 people have browsed it

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:

Interface :

 get
guestbook/index.php
m : index
a : verifyUserName
username : 要验证的用户名
Copy after login

Return :

{
code : 返回的信息代码 0 = 没有错误,1 = 有错误
message : 返回的信息 具体返回信息
}
Copy after login

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'; //正确信息加绿色
}
});
}
Copy after login

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template