日期:2014-05-16 浏览次数:20660 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>itcast.cn用户校验的ajax</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="jslib/jquery.js"></script>
<script type="text/javascript" src="jslib/verify.js">
</script>
</head>
<body>
用户名校验的ajax实例,请输入用户名:<br/>
<input type="text" id="userName"/>
<input type="button" value="校验" onclick="verify()"/>
<div id="result">
</div>
</body>
</html>
function verify()
{
// document.getElementsByName("userName");
// document.getElementById("userName");
// alert("userName)");
// jquery的查找节点的值的方式
var jqueryObj = $("#userName");
var userName = jqueryObj.val();
// alert(userName);
$.get("AJAXServer?name=" +userName,null,callback);
}
function callback(data)
{
// alert("服务器端的数据回来了");
// alert(data);
var resultObj = $("#result");
resultObj.html(data);
alert("");
}
package cn.itcast.project;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
public class AjaxServlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
try
{
// request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
&n