注册 | 登录 | 设为首页 | 加入收藏
您当前的位置:飞翔学院-IT中国 → 编程开发AJAX → 文章内容

利用AjAX动态变换过滤条件

作者:佚名 来源:不详 发布时间:2007-12-10 22:11:32

在我的一个java项目中,需要在数据列表的上面添加过滤功能,可且根据用户选择的过滤条件,来生成不同过滤脚本:
//**********************以下是表格的第一行脚本***************************//
   <TD align="center" width="15%" height="25">选择查询条件:</TD>
 <TD align="left" width="30%"><select name="FilterName" id="FilterName"
  style="width:100%" >
  <option value=""></option>
        <option value='BugInfo_Title' <%=BugInfoList.getSelected("BugInfo_Title")%>>Bug标题</option>
        <option value='BugInfo_BugUser' <%=BugInfoList.getSelected("BugInfo_BugUser")%>>安装用户</option>
        <option value='BugInfo_BugSystem' <%=BugInfoList.getSelected("BugInfo_BugSystem")%>>安装系统</option>
        <option value='BugInfo_BugTime' <%=BugInfoList.getSelected("BugInfo_BugTime")%>>提交时间</option>
        <option value='BugInfo_DoneTime' <%=BugInfoList.getSelected("BugInfo_DoneTime")%>>完成时间</option>
    </select></TD>
 <TD align="left" width="37%" id="filter"><%=BugInfoList.getFilterHtml()%></TD>
    <TD align="center" width="18%"><A class="TextUrl9" href="javascript:doFilter();">
     <IMG src="/html/UploadPic/2007-12/20071210221132528.gif" align="absMiddle" border="0">开始过滤</A>
       <A class="TextUrl9" href="javascript:doAll();"><IMG
     src="/html/UploadPic/2007-12/20071210221133125.gif" align="absMiddle" border="0">全部</A>
    </TD>
  </TR>
//*********************************以下是JavaScript脚本******************************************************//
 /*获取客户端XMLHttpRequest请求对象*/
 function getRequest(){
    var request = false;
    try {
        request = new XMLHttpRequest();
    } catch (trymicrosoft) {
        try {
         request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (othermicrosoft) {
         try {
             request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (failed) {
             request = false;
         } 
        }
    }
    if (!request) alert("错误初始化XMLHttpRequest对象!");
    return request;
 }
    var request=getRequest();
    //改变过滤条件
 function changeFilter() {
      if(request==null) request=getRequest();
      var name = FrmBugInfo.FilterName.value;
      var url ="../ajaxFilter?name="+name;
      request.onreadystatechange = updateFilter;
      request.open("GET", url, true);
      request.send(null);
   }
   //改变过滤条件
   function updateFilter(){
      if (request.readyState == 4) {
         if (request.status == 200) {
            var text=request.responseText;
            document.getElementById("filter").innerHTML=text;
         } else{
            alert("状态是:" + request.status);
         }
         delete request['onreadystatechange'];
         request=null;//必须清空
      }
   }
//*********************************以下是ajaxFilter源码,它是一个servlet*********************************************//
    static final String[] TIME={"smalldatetime","datetime","timestamp"};
    static final String[] NUM ={"tinyint","smallint","int","bigint","decimal","numeric",
                                 "float","real","smallmoney","money","binary",};
    static final String SQL   ="select * from DataDict where TableName='%s' and FieldName='%s'";
    static final String DEFAULT="<input type='text' name='FilterValue' id='FilterValue' value='@value' style='width:100%'></input>";
    static final String DATE   ="<input id=\"@name\" type=\"text\" name=\"@name\" value='@value' \n"
                                +"         class=\"TextBox\" readonly=\"readonly\" style=\"width:100px;\"/> \n"
                         +"         <IMG style=\"CURSOR: hand\" onclick=\"showtime(@name)\"\n"
                                +"         alt=\"选择日期\" src=\"../images/image/date.gif\" width='16' align='middle'>";
                               
    //doGet和doPost中的源码
    response.setContentType(CONTENT_TYPE);
    PrintWriter out=response.getWriter();
    String name=request.getParameter("name");
    out.print(PageList.getFilter(name));
       


更多内容请看PCdog.com--Ajax技术专题
[1] [2]  下一页


  • 打印文档
  • 推荐好友
  • 返回顶部
  • 增大字体
  • 减少字体
关于本站 | 工作机会 | 合作网站 | 广告服务 | 市场合作| 联系我们 | 抽奖活动
版权所有: 武汉威俊科技有限公司 Copyright 2005-2007 www.ITCNW.COM All rights reserved