ajax问题!
package com.soes.servlet;import
import
import java.util.ArrayList;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.soes.dao.Empdao;
public class AjaxServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException{}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String d_short = request.getParameter("d_short");
//设置输出信息的格式及字符集
response.setContentType("text/xml; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
// 创建输出流对象
PrintWriter out = response.getWriter();
out.println("<response>");
Empdao eDao = new Empdao();
ArrayList eList = null;
if(d_short.equalsIgnoreCase("all")){
eList = eDao.getAllEmpId();
}else{
eList = eDao.getEmpByD_short(d_short);
}
for(int i=0;i<eList.size();i++)
{
out.println("<eid>" + eList.get(i) + "</eid>");
}
out.println("</response>");
out.close();
}
}
function getEmpID(a,b)
{
var d_short = document.getElementById(a).value;
e_id = b;
createXMLHttpRequest();
var url = "http://localhost:8080/demoAjax/AjaxServlet?d_short="+d_short;
XMLHttpReq.open("GET",url,true); //向服务器发送请求
XMLHttpReq.onreadystatechange = Emp; //将对象状态与事件相关联
XMLHttpReq.send(null);
}
function Emp()
{
if(XMLHttpReq.readyState == 4) //判断接受到的响应的状态,如果是4加载完毕
{
if(XMLHttpReq.status == 200)
{
var node = XMLHttpReq.responseXML.getElementsByTagName("eid");
var DeptEmpID = document.getElementById(e_id);
DeptEmpID.length = 0;
DeptEmpID.options[0] = new Option('--------所有员工--------','all');
for(var i = 0;i< node.length; i++)
{
var emp = node[i].firstChild.data;
DeptEmpID.options[i+1] = new Option(emp,emp);
}
}else{
alert("页面有异常;XMLHttpReq.status:"+XMLHttpReq.status);
}
}else{
//alert("请求加载中,XMLHttpReq.readyState:"+XMLHttpReq.readyState);
}
}
var node = XMLHttpReq.responseXML.getElementsByTagName("eid"); 获取那里的属性
var emp = node[i].firstChild.data;这一段代码是什么意思
上面的方法是获取什么的!!!请教
[[it] 本帖最后由 qiuqiu2641847 于 2008-11-23 22:34 编辑 [/it]]