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

Ajax verification username example code

Jan 10, 2018 am 09:59 AM
ajax code Example

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the blue screen code 0x0000001 occurs What to do if the blue screen code 0x0000001 occurs Feb 23, 2024 am 08:09 AM

What to do if the blue screen code 0x0000001 occurs

Resolve code 0xc000007b error Resolve code 0xc000007b error Feb 18, 2024 pm 07:34 PM

Resolve code 0xc000007b error

GE universal remote codes program on any device GE universal remote codes program on any device Mar 02, 2024 pm 01:58 PM

GE universal remote codes program on any device

What does the blue screen code 0x000000d1 represent? What does the blue screen code 0x000000d1 represent? Feb 18, 2024 pm 01:35 PM

What does the blue screen code 0x000000d1 represent?

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

How to solve the 403 error encountered by jQuery AJAX request

How to solve jQuery AJAX request 403 error How to solve jQuery AJAX request 403 error Feb 19, 2024 pm 05:55 PM

How to solve jQuery AJAX request 403 error

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

How to get variables from PHP method using Ajax?

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Jun 12, 2024 pm 08:38 PM

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing

See all articles