
已解决问题
谷歌kanlingyou用户在2016.04.20提交了关于“贵士后台怎么接收ajax传过来的**”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2025-03-02T20:34:58。希望大家能够帮助她。详细问题描述及疑问:期待您的答案,没有什么华丽的语言,但是我对你的感谢不会减少 !
详细问题描述及疑问:期待您的答案,没有什么华丽的语言,但是我对你的感谢不会减少 !
接收ajax传过来的数
客户端搭纳手代码:
<scripttype="text/
functioncheckUser(ouser){
varuname=ouser.value;
if(!uname){
alert("用户名
ouser.focus;
}
//发送
//Ajax代码实现
/
//请求
/arurl="servl
varurl="servlet/doRe
varuserinfo="uname="+uname
//1.创建XMLh**ttpRequest组件
xmlh**t
/
xm
//3.初始化XMLh**ttpRequest组件
//*
***.open("P
xmlh**tt
//4.发送请求
xml
}
function
if(xmlh**ttpRequest.readyState==4
&&xmlh**ttpRequest.status==200){
varb=xmlh**ttpReque
b=b.replace(/(^\s*)|(\s*$)/g,"");
if(b=="true"){
alert("用户名已经存
}else{
alert("用
}
}
}
functioncreateXmlh**t
if(window.X
returnnewXMLh**ttpReq
}else{//老版本IE浏览器(包括IE5和
returnn
}
}
</script>
服务器端代
publicvoiddoGet(h**ttpSe
h**
response.setContentType("textml;charset=utf-8");
PrintWriterout=response.getWriter();
Stringuname=request.getParameter("uname");
System.out.println(uname);
booleanuExists=false;
if(uname.equals("hdjr"))
{uExists=true;
out.print(uExists);
}else{
out.print(uExists);
}
out.flush();
out.close();
}
/**
*ThedoPostmethodoftheservlet.<br>
*
*Thismethodiscalledwhenaformhasitstagvaluemethodequalstopost.
*
*@paramrequesttherequestsendbytheclienttotheserver
*@paramresponsetheresponsesendbytheservertotheclient
*@throwsServletExceptionifanerroroccurred
*@throwsIOExceptionifanerroroccurred
*/
publicvoiddoPost(h**ttpServletRequestrequest,h**ttpServletResponseresponse)
throwsServletException,IOException{
doGet(request,response);
}