Home > Web Front-end > JS Tutorial > body text

jquery ajax 登录验证实现代码_jquery

WBOY
Release: 2016-05-16 18:46:08
Original
986 people have browsed it

使用 jquery 框架:下载 jquery.js
新建一个 web 工程 ajax ;
在 webRoot 下新建一个 jslib 文件夹:专门存放 js 文件;
在 webRoot 下新建一个 html/jsp 页面:
login.html

复制代码 代码如下:


在 jslib 下新建一个 js 文件:
verify.js ;
复制代码 代码如下:

function verify()
{
var paramObj=encodeURI(encodeURI($( "#username" ).val()));
$.get( "TestSvlt?username=" +paramObj, null ,callback);
}
function callback(data)
{
var resultObj=$( "#result" );
resultObj.html(data);
}

新建一个 servlet : AjaxLogin 类;在 doGet 方法中写
复制代码 代码如下:

response.setContentType( "text/html;charset=utf-8" );
PrintWriter out=response.getWriter();
String name=request.getParameter( "username" );
String username= URLDecoder.decode (name, "UTF-8" );
System. out .println(username);
if ( null ==username|| "" .equals(username))
{
out.print( "username is not null" );
}
else
{
if (! "lej" .equals(username))
{
out.print(username+ " not existing" );
}
else {
out.print(username+ " login successs" );
}
}
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