日期:2014-05-17  浏览次数:20818 次

【100分】ajax在jsp页面接受不到数据
大家帮我看看是哪的问题啊 ,我刚接触ajax
-------jsp页面--------
var xmlHttp;
function createXMLHttpRequest()
{
  if(window.XMLHttpRequest){ 
   xmlHttp = new XMLHttpRequest();
  if(xmlHttp.overrideMimeType){
   xmlHttp.overrideMimeType('text/xml');
   }
  }else if(window.ActiveXObject){  
   try {
   xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");} catch(e){
   try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}catch(e){

}
   }
  }
  if (!xmlHttp)
  { 
   window.alert("不能创建XMLHttpRequest对象实例.");
   return false;
  }
}

function getCheckData(name,value){
  if(name=="kdid"){  
createXMLHttpRequest();
var url="../xtgl/itsDuanMianAction.do?method=returnDuanMianList&kdid="+value;
xmlHttp.open("post", url, false);
xmlHttp.setRequestHeader("Content-Type","text/xml;charset=GB2312") ;
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);  
  }  
}

function callback(){
if(xmlHttp.readyState == 4) 
{
if(xmlHttp.status == 200) 
{
var sel_area=document.getElementById("sel_dmid");
var info="<select name='dmid' id='sel_dmid' length='50' style='width:140' onclick='getCheckData(this.name);'>";
var xml=xmlHttp.responseXML;
var nodesValue=xml.getElementsByTagName("value");
var nodesKey=xml.getElementsByTagName("key");
var size=nodesValue.length;
alert("---xml----- "+xml);
alert("-------size---- "+size);
if(size>0){  
for(i=0;i<size;i++){  
info+="<option value="+nodesValue[i].text+">"+nodesKey[i].text+"</option>";
}
}else{  
info+="<option value=''>全部</option>";
}
info+="</select>";
sel_area.outerHTML=info;
}
}
}

-------类文件--------
public void returnDuanMianList (ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)throws IOException, ServletException
{
java.util.List list = null;
String kdid="";
ItsDuanmian itsduanmian;
httpServletResponse.setContentType("text/xml; charset=UTF-8"); 
httpServletResponse.setHeader("Cache-Control", "no-cache"); 
try
{ PrintWriter out = httpServletResponse.getWriter(); 
kdid=httpServletRequest.getParameter("kdid");
ItsDuanMianActionForm itsDuanMianActionForm = (ItsDuanMianActionForm)actionForm;
  ArrayOfItsDuanmian lstDuanMian = new ArrayOfItsDuanmian();
SRV_itsClient client = new SRV_itsClient();
SRV_itsPortType service = client.getSRV_itsHttpPort();
lstDuanMian = service.getDuanMianList("E",kdid,1,100000);
  list=lstDuanMian.getItsDuanmian();  
  for(int i=0;i<list.size();i++){
  itsduanmian=new ItsDuanmian();
  itsduanmian=(ItsDuanmian) list.get(i);
  out.println("<value>