利用AjAX动态变换过滤条件

2008-02-23 09:12:41来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

在我的一个Java项目中,需要在数据列表的上面添加过滤功能,可且根据用户选择的过滤条件,来生成不同过滤脚本:
//**********************以下是表格的第一行脚本***************************//
<TD align="center" width="15%" height="25">选择查询条件:</TD>
<TD align="left" width="30%"><select name="FilterName" id="FilterName"
style="width:100%" onchange="JavaScript:changeFilter();">
<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="../images/image/chaxun.gif" align="absMiddle" border="0">开始过滤</A>
&nbsp;&nbsp;<A class="TextUrl9" href="javascript:doAll();"><IMG
src="../images/image/cx.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);

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:WebLogic下JSP连接数据库

下一篇:移植IEWebControls到Java开发环境