$.get(url, [data], [callback], [type])
urlString
待载入页面的URL地址
data (可选)Map
待发送 Key/value 参数。
callback (可选)Function
载入成功时回调函数。
type (可选)String
返回内容格式,xml, html, script, json, text, _default。
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>jquery用户名校验</title>
<script type="text/javascript" src="js/verify.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<h2>用户名校验</h2>
账号:<input type="text" id="name" onblur="mycheck()"> <span id="tips"></span>
</body>
</html>
js
function mycheck(){
//取得用户名对象
var uname=$("#name").val();
//发送数据
$.get("nametest?name="+uname,null,callback);
}
function callback(data){
$("#tips").html(data);
}
public class HelloAction extends ActionSupport{
private String name;
HttpServletResponse response;
public String execute() throws Exception {
response=ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
PrintWriter out=response.getWriter();
if(name.equals("hanqing")){
out.println("用户名已经存在");
}
else {
out.println("用户名可以使用");
}
return null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}