jquery的回调函数不起作用

zr_dixuexiongying 2012-06-14 11:47:29
我用jquery的$.get获取servlet的值,最后一个回调函数怎么不起作用啊

AjaxServlet.java代码

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
{
response.setContentType("text/html;charset=utf-8");

PrintWriter out = response.getWriter();

String name = request.getParameter("name");

if(name == null || name.length() == 0)
{
out.println("用户名不能为空");
}else
{
if(name.equals("wujunjie"))
{
out.println("用户名["+name+"]已经存在,请使用其他账户登录");
}else
{
out.println("用户名["+name+"]尚未存在,可以使用该用户登录");
}
}

}catch(Exception ex)
{
ex.printStackTrace();
}

}

protected void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
doGet(request,response);
}


}

ajax.html页面

<!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>
itcast.cn用户名校验的ajax实例,请输入用户名:<br/>
<input type="text" id="userName"/>
<input type="button" value="校验" onclick="verify()"/>

<div id="result">
</div>
</body>
</html>


verify.js
function verify()
{
// document.getElementsByName("userName");
// document.getElementById("userName");
// alert("userName)");
// jquery的查找节点的值的方式
var jqueryObj = $("#userName");
var userName = jqueryObj.val();
// alert(userName);

$.get("AjaxServlet?name=" +userName,null,callback);
}

function callback()
{
alert("服务器端的数据回来了"); //测试
}
...全文
171 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
001007009 2012-06-14
  • 打赏
  • 举报
回复
firebug 调试下 看什么错误
zr_dixuexiongying 2012-06-14
  • 打赏
  • 举报
回复
对了,我的jquery版本是 1.7的

52,782

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧