js代码:
var xhr = getXhr();
function getXhr(){
var xhr = null;
try {
xhr = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
xhr = false;
}
}
}
if (!xhr) {
alert("err Happend!");
}
return xhr;
}
function check() {
var user = document.getElementById("user").value;
var url = "RegisterServlet?id=" + user;
if (xhr.readyState == 4 && xhr.status == 200) {
var str = xhr.responseText;
if (str=="OK") {
document.getElementById("checkname").innerHTML="用户名可用";
} else {
doucument.getElementById("checkname").innerHTML="用户名重复";
}
}
xhr.open('get',url,true);
xhr.send(null);
}
前端代码:
servlet代码:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("utf-8");
PrintWriter out=response.getWriter();
String username=request.getParameter("id");
System.out.println(username);
if(username.equals("1")){
out.println("OK");
}else {
out.println("NO");
}
}
我测试用户名输入是否为1来判断,从servlet传值过来,但是在jsp里面span标签那显示不出来信息,
测试显示这个错误:
ReferenceError: doucument is not defined,报错行数在js的if判断innerhtml行
各位大大帮忙看看