源码百度云下载地址:http://pan.baidu.com/s/1jIbDYkQ
创建Ajax引擎
同上节
发送Ajax请求
//验证@R_301_473@ functioncheckUserName(){ createXmlHttpRequest(); if(xmlHttpRequest){ varuserName=document.getElementById("userName").value; //请求URL varurl="Regedit"; //数据 vardata="userName="+encodeURI(encodeURI(userName)); //提交请求 xmlHttpRequest.open("post",url,true); //回调函数 xmlHttpRequest.onreadystatechange=chuli; //使用post提交时必须加上下面这行代码 xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); //发送请求 xmlHttpRequest.send(data); } }
后台服务器处理
protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse) throwsServletException,IOException{ //返回数据编码 response.setContentType("text/html;charset=utf-8"); //打印数据到前台 PrintWriterout=response.getWriter(); //获取@R_301_473@ StringuserName=URLDecoder.decode(request.getParameter("userName"),"UTF-8"); //模拟数据库请求,假如有个@R_301_473@为xukaiqiang. if(userName.equals("xukaiqiang")){ out.print(userName+"@R_301_473@重复"); }else{ out.print(userName+"@R_301_473@可以使用"); } out.close(); }
同上节