后台怎么接收ajax传过来的**

时间:2016.04.20 发布人:kanlingyou

后台怎么接收ajax传过来的**

已解决问题

谷歌kanlingyou用户在2016.04.20提交了关于“贵士后台怎么接收ajax传过来的**”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2025-03-02T20:34:58。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,没有什么华丽的语言,但是我对你的感谢不会减少 !

希望以下的回答,能够帮助你。

第1个回答

用户名:okpl来自m  

接收ajax传过来的数送物失委决青个据

客户端搭纳手代码:
<scripttype="text/j**ascript"茄胡>
functioncheckUser(ouser){
varuname=ouser.value;
if(!uname){
alert("用户名完钱握简油空不能为空");
ouser.focus;
}
//发送请求到服务器,判断用户名是否存在
//Ajax代码实现
/331215问答/发送请求到服务器,判断用户名是否存在
//请求字符串
/arurl="servl湖映顾检降宁慢et/doReg?uname="+uname;//GET方式
varurl="servlet/doRe错德占讲g";//POST方式
varuserinfo="uname="+uname究超束想燃离次;
//1.创建XMLh**ttpRequest组件
xmlh**t课游促角刘组粉时表果最tpRequest=c免物束危远reateXmlh**ttpRequest();
/指货更约参士盐/2.设置回调函数
xm定孩职格lh**ttpRequest.onreadystatechange=haoLeJiaoWo;
//3.初始化XMLh**ttpRequest组件
//***.open("GET",url,true);//GET方式
***.open("POST",url,true);//POST方式
xmlh**ttpRequest.setRequesth**eader("Content-Type","application/x-www-form-urlencoded");//POST方式需要设置
//4.发送请求
xmlh**ttpRequest.send(userinfo);
}
function也给破haoLeJiaoWo(){
if(xmlh**ttpRequest.readyState==4
&&xmlh**ttpRequest.status==200){
varb=xmlh**ttpRequest.responseText;
b=b.replace(/(^\s*)|(\s*$)/g,"");
if(b=="true"){
alert("用户名已经存在");
}else{
alert("用户名可以使用");
}
}
}
functioncreateXmlh**ttpRequest(){
if(window.XMLh**ttpRequest){//新版本IE浏拿急览器(IE7及以上版本)或其他浏览知嫌器
returnnewXMLh**ttpReq为丰发轻善医量uest();
}else{//老版本IE浏览器(包括IE5和食波照这掌活培IE6)
returnnewActiveXObject("Microsoft.XMLh**TTP");
}
}
</script>

服务器端代初刚码:
publicvoiddoGet(h**ttpServletRequestrequest,
h**ttpServletResponseresponse)
化故伯厚飞哥存扬迫比throwsServlet仍据少Exception,I示罪OException{
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);
}