标签:parameter rms int send 设置 null mic val microsoft
var xmlHttpRequest = null; //1、创建XMLHttpRequest对象 if (window.XMLHttpRequest) {//新版本返回为TRUE xmlHttpRequest = new XMLHttpRequest(); } else { xmlHttpRequest = new ActiveXObject( "Microsoft.XMLHTTF"); } //2、设置回调函数 xmlHttpRequest.onreadystatechange = callBack; var username = $("#username").val(); //3、初始化XMLHttpRequest组件 var url = "UserServlet?username=" + username; xmlHttpRequest.open("GET", url, true); //4、发送请求 xmlHttpRequest.send(null); //回调函数callBack的编写 function callBack() { if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) { var data = xmlHttpRequest.responseText; if (data == "true") { $("#errMsg").html("用户名已被注册"); } else { $("#errMsg").html("用户可以注册"); } } } });
package com.niu.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class UserServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String name = req.getParameter("username"); boolean used = false; if ("ajax".equals(name)) { used = true; } resp.setContentType("text/html;charset=utf-8"); PrintWriter out = resp.getWriter(); out.print(used); out.flush(); out.close(); } }
标签:parameter rms int send 设置 null mic val microsoft
原文地址:http://www.cnblogs.com/binglong180/p/7967083.html