0

我需要刷新浏览器的某些部分。因此,我正在使用 Ajax。当我使用 GET 方法时,我可以在服务器上看到数据,但是当我使用 POST 时,我不能。请问有什么指点吗?

------------ searchPan.jsp 的代码--------------

<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>

---------------------------------------- GET 代码-------- -----------------

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();
}

当我使用 GET 方法时,我得到以下输出

url is /cardsit/promo/card/searchPan.jsp
pan is pan=123456789
pan is 123456789

When I use POST, I am unable, .. as below.
url is /cardsit/promo/card/searchPan.jsp
pan is null
pan is null

---------------------- POST 代码---------------------------- ---

xmlhttp.open("POST", "searchPan.jsp", true);
  var queryString = 'searchPan.jsp';
  queryString = 'pan=' + document.getElementById('pan_number').value;
  alert(queryString);
  xmlhttp.send(queryString);

4

2 回答 2

1

添加这一行,它上次帮助了我。

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
于 2013-05-13T07:28:48.330 回答
0

试试下面的代码

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);
于 2013-05-13T07:28:55.230 回答