若发送带参数的post请求时必须加上下面这段代码告知服务器将会有参数传过来,不然后台用request.getParameter()将无法获取。
要用getreader()或getInputStream()获取了。
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
发送同步的Ajax具体代码如下:
function checkRegistedTime() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest; } else { xmlhttp = new ActiveObject("Microsoft.XMLHTTP"); } var registedday = document.getElementById("registeddayDataBase").value; var registedtime = document.getElementById("registedtime").value; /* var url = "registedTime_validate.jsp?registedday=" + registedday + "®istedtime=" + registedtime; */ var url = "registedTime_validate.jsp"; var data = "registedday=" + registedday + "®istedtime=" + registedtime; xmlhttp.open("post",url,false); xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.send(data); return xmlhttp.responseText; }
后台获取数据代码registedTime_validate.jsp:
<% String registeddayDataBase = request.getParameter("registeddayDataBase"); String registedtime = request.getParameter("registedtime"); %>
原文链接:https://www.f2er.com/ajax/161390.html