标题:ajax问题!
只看楼主
qiuqiu2641847
Rank: 1
来 自:湖北襄樊
等 级:新手上路
帖 子:22
专家分:0
注 册:2008-5-8
 问题点数:0 回复次数:2 
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]]
搜索更多相关主题的帖子: ajax 
2008-11-23 21:56
huwangvs
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:764
专家分:0
注 册:2007-2-4
得分:0 
var node = XMLHttpReq.responseXML.getElementsByTagName("eid"); 获取<eid>
var emp = node[i].firstChild.data;获取node下面的第一个孩子里面的数据。。。。
2008-11-24 09:16
qiuqiu2641847
Rank: 1
来 自:湖北襄樊
等 级:新手上路
帖 子:22
专家分:0
注 册:2008-5-8
得分:0 
回复 第2楼 huwangvs 的帖子
thank you !
2008-11-24 22:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-245912-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.154836 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved