jsp Ajax获取工作日志不工作
我需要刷新浏览器的某些部分。因此,我使用Ajax。当我使用GET方法时,我可以在服务器上看到数据,但当我使用POST时,我无法看到数据。 有什么建议吗 -----------searchPan.jsp的代码-------------------------jsp Ajax获取工作日志不工作,ajax,jsp,tomcat6,Ajax,Jsp,Tomcat6,我需要刷新浏览器的某些部分。因此,我使用Ajax。当我使用GET方法时,我可以在服务器上看到数据,但当我使用POST时,我无法看到数据。 有什么建议吗 -----------searchPan.jsp的代码------------------------- <html> <% try { System.out.println("url is " + request.getRequestURI()); System.out.pr
<html>
<%
try
{
System.out.println("url is " + request.getRequestURI());
System.out.println("pan is " + request.getQueryString());
System.out.println("pan is " + request.getParameter("pan"));
}
catch(Exception E)
{
System.out.println("Error happened " + E);
}
//promo_card cardobj = new promo_card();
//out.println(cardobj.getData());
%>
</html>
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==0)
document.getElementById('status').innerHTML='Uninitialized';
else if(xmlhttp.readyState==1)
document.getElementById('status').innerHTML='Loading...';
else if(xmlhttp.readyState==2)
document.getElementById('status').innerHTML='Loaded';
else if(xmlhttp.readyState==3)
document.getElementById('status').innerHTML='Interactive';
else if(xmlhttp.readyState == 4 && xmlhttp.readyState == 200)
document.getElementById("div1").innerHTML = xmlhttp.responseText;
}
if(xmlhttp)
{
var queryString = 'searchPan.jsp?pan=' + document.getElementById('pan_number').value;
xmlhttp.open("GET", queryString, true);
xmlhttp.send();
}
xmlhttp.open("POST", "searchPan.jsp", true);
var queryString = 'searchPan.jsp';
queryString = 'pan=' + document.getElementById('pan_number').value;
alert(queryString);
xmlhttp.send(queryString);
当我使用GET方法时,我得到以下输出
----------------------邮政编码----------------------------
<html>
<%
try
{
System.out.println("url is " + request.getRequestURI());
System.out.println("pan is " + request.getQueryString());
System.out.println("pan is " + request.getParameter("pan"));
}
catch(Exception E)
{
System.out.println("Error happened " + E);
}
//promo_card cardobj = new promo_card();
//out.println(cardobj.getData());
%>
</html>
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==0)
document.getElementById('status').innerHTML='Uninitialized';
else if(xmlhttp.readyState==1)
document.getElementById('status').innerHTML='Loading...';
else if(xmlhttp.readyState==2)
document.getElementById('status').innerHTML='Loaded';
else if(xmlhttp.readyState==3)
document.getElementById('status').innerHTML='Interactive';
else if(xmlhttp.readyState == 4 && xmlhttp.readyState == 200)
document.getElementById("div1").innerHTML = xmlhttp.responseText;
}
if(xmlhttp)
{
var queryString = 'searchPan.jsp?pan=' + document.getElementById('pan_number').value;
xmlhttp.open("GET", queryString, true);
xmlhttp.send();
}
xmlhttp.open("POST", "searchPan.jsp", true);
var queryString = 'searchPan.jsp';
queryString = 'pan=' + document.getElementById('pan_number').value;
alert(queryString);
xmlhttp.send(queryString);
添加这一行,上次它帮助了我
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
请尝试以下代码
xmlhttp.open("POST", "searchPan.jsp", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var queryString = 'pan=' + document.getElementById('pan_number').value;
xmlhttp.send(queryString);
哇!成功了。url为/cardsit/promo/card/searchPan.jsp pan为空pan为123456789