ajax请求得到后台数据,前台页面,使用table模板然后clone,显示表格,,不用append拼接 “字符串和HTML表格标签”

<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<%
String path = request.getcontextpath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>
<script type="text/javascript" src=\'#\'" /js/jquery-1.11.1.min.js"></script>

<style>
</style>
<script>
$(document).ready(function() {
//搜索按钮(全部搜索和按条件搜索
$("#searchBtn").click(function(){
var itemname = $("#itemname").val();
var year = $("#year option :selected ").val();
//当输入框为空,年份没选择,就为搜索全部数据
if(itemname =="" && year == undefined){
$.get("<%=request.getcontextpath()%>/searchAll",
function(data){
$.each(data.tasklist,function(i,obj){
/* 获取数据,添加给模板表格 */
$("#temp_table #temp_tr #id").text(obj.id);
$("#temp_table #temp_tr #name").text(obj.name);
$("#temp_table #temp_tr #type").text(obj.type);
$("#temp_table #temp_tr #cost").text(obj.cost);
$("#temp_table #temp_tr #state").text(obj.state);
$("#temp_table #temp_tr #date").text(obj.date);
/*复制模板表格,并插入到指定位置,参数true,表示CSS和事件也克隆 */
$("#temp_table #temp_tr").clone(true).insertAfter("#is_header");
});
});
}

});
});
</script>

</head>

<body>




<!-- 表格模板---用于处理获取后台数据后生成表格, -->
<div id="temp" style="display: none;">
<table id="temp_table">
<tr id="temp_tr">
<td id="id" width="5%" height="25" align="center" bgcolor="#EFFBFE">aa</td>
<td id="name" align="center" bgcolor="#EFFBFE">bb</td>
<td id="type" colspan="2" align="center" bgcolor="#EFFBFE">cc</td>
<td id="cost" align="center" bgcolor="#EFFBFE">dd</td>
<td id="date" align="center" bgcolor="#EFFBFE">ff</td>
<td id="state" align="center" bgcolor="#EFFBFE">ee</td>
<td align="left" bgcolor="#EFFBFE">
<div align="left" style="padding-left: 5px">
<div align="center">
<input name="edit" type="button" value="编辑" /> &nbsp;
<input name="delete" type="button" value="删除"/>
</div>
</div>
</td>
</tr>
</table>
</div>





<!-- 以下是显示页面内容-->
<table width="99%" height="25" border="0" align="center"
cellpadding="0" cellspacing="0" style="margin-bottom: 4px;">
<tr>
<td width="17" background="images/bj4.gif"><img
src="Picture/r.gif" width="16" height="16" /></td>
<td width="466" background="images/bj4.gif">张宇(学院申报者):你好!欢迎光临,您上次登录时间是:2015-09-20
23:15:15</td>
<td width="162" align="center" background="images/bj4.gif"></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="1%" align="left" background="images/b2.jpg"><img
src="Picture/b1.jpg" width="10" height="26" /></td>
<td width="68%" background="images/b2.jpg"><table width="124"
border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="20" align="left"><img src="Picture/tz.gif"
width="10" height="16" /></td>
<td width="104" align="left" class="biao">项目搜索</td>
</tr>
</table></td>
<td width="31%" align="right" background="images/b2.jpg"><img
src="Picture/b3.jpg" width="9" height="26" /></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="3"
cellspacing="1" bgcolor="#AEDEF4">
<tr>
<td align="center" bgcolor="#E2F7FE">
<form id="form1" name="form1" method="post"
action="<%=path%>/searchByYear">
<table width="50%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="10%" height="25" align="center">项目名称:</td>
<td width="14%" align="left"><label> <input
name="itemname" type="text" id="itemname" size="20" />
</label></td>
<td width="6%" align="center">年份:</td>
<td width="14%" align="left"><select name="year" id="year">
<option value="">全部</option>
<option value='2009'>2009</option>
<option value='2010'>2010</option>
<option value='2011'>2011</option>
<option value='2012'>2012</option>
<option value='2013'>2013</option>
<option value='2008'>2008</option>
<option value='2014'>2014</option>
<option value='2015'>2015</option>
<option value='2016'>2016</option>
<option value='2017'>2017</option>
</select></td>
<td width="8%"><input type="button" id="searchBtn"
name="searchBtn" value="搜索" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="5"></td>
</tr>
</table>
<table width="99%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="1%" align="left" background="images/b2.jpg"><img
src="Picture/b1.jpg" width="10" height="26" /></td>
<td width="68%" background="images/b2.jpg"><table width="124"
border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="20" align="left"><img src="Picture/tz.gif"
width="10" height="16" /></td>
<td width="104" align="left" class="biao">项目列表</td>
</tr>
</table></td>
<td width="31%" align="right" background="images/b2.jpg"><img
src="Picture/b3.jpg" width="9" height="26" /></td>
</tr>
</table>
<!-- 这里是获取后台数据,并画出显示表格 -->
<table id="is_table" width="99%" border="0" align="center"
cellpadding="3" cellspacing="1" bgcolor="#AEDEF4"
style="border: 1px solid #AEDEF4">

<tr id="is_header">
<td width="5%" height="25" align="center" bgcolor="#EFFBFE">ID</td>
<td align="center" bgcolor="#EFFBFE">项目名称</td>
<td colspan="2" align="center" bgcolor="#EFFBFE">项目类型</td>
<td align="center" bgcolor="#EFFBFE">申请经费</td>
<td align="center" bgcolor="#EFFBFE">提交时间</td>
<td align="center" bgcolor="#EFFBFE">状态</td>
<td align="center" bgcolor="#EFFBFE">管理操作</td>

</tr>


<!-- 克隆的模板表格,粘贴到这里 -->

<tr> <td height="25" bgcolor="#FFFFFF">&nbsp;</td> <td colspan="6" bgcolor="#FFFFFF"><span class='pagelink'>首页</span> <span class='pagelink'>上一页</span> <span class='pagelink'>下一页</span> <span class='pagelink'>尾页</span> &nbsp;&nbsp;转到第&nbsp; <input id='jumpSelect' type='text' size='2' value='1' />页</td> <td bgcolor="#FFFFFF"> </td> </tr> </table> </body> </html>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但是在某些特殊情况下,我们可能还需要使用IE6来访问网页。而在IE6中,我们通常会使用JavaScript来提交表单,来看一下具体操作。
PHP中的count()函数是用来计算数组或容器中元素的个数。这个函数十分方便,在编写代码时使用频率也非常高。无论你是要统计数组的长度、统计字符串中字符出现的次数还是统计对象中属性的个数,count()都可以帮助你轻松
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不刷新整个页面的情况下,向服务器发送请求并接收响应。通常来说,我们使用 AJAX 请求是为了获取后台数据,并将其展示在前端页面上。然而,有时候我们只需要
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页用户体验的技术,通过与服务器进行异步通信,实现在网页上局部刷新数据而不必整个页面刷新的功能。在实际开发中,我们经常需要从服务器端下载文件,而传统
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以在不刷新整个页面的情况下,向服务器发送请求并获取响应数据。在某些场景下,我们需要通过AJAX下载Excel文件流,以便于在前端使用或保存到本地。本文将详
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax,我们可以在不刷新整个页面的情况下向服务器发送请求并获得响应数据。而在Ajax的基础上,.get和.post是两种常用的请求方法,它们分别用于发送GET和POST请
AJAX(Asynchronous JavaScript and XML)是一种在网页上实现异步数据传输的技术。通过AJAX,网页可以在不刷新整个页面的情况下与服务器进行数据交互,提升用户体验和页面性能。在实际应用中,AJAX广泛用于表单提交、
在使用Ajax下拉加载数据的过程中,有时候会出现无法取到360度的问题。这个问题可能是由于代码逻辑的问题导致的,也有可能是网络延迟引起的。为了解决这个问题,我们需要对代码进行仔细排查,并且在合适的地方添加适当
本文将介绍Ajax和.post之间的区别。Ajax是一种用于在网页上进行异步通信的技术,能够在不刷新整个页面的情况下更新部分页面内容。.post是jQuery中的一个方法,用于向服务器发送POST请求。虽然它们都可以用于发送异步
AJAX(Asynchronous JavaScript and XML)是一种在Web页面上进行异步数据请求和交互的技术。它的出现使得页面在后台与服务器进行数据交互的同时,不需要重新加载整个页面。在网页开发中,常常需要实现文件上传功能,
最近,我对于在IE浏览器中使用Ajax上传文件进行了一番研究。我发现IE浏览器对于Ajax上传文件提供了支持,并且使用起来也相对简单。事实上,我们可以使用ActiveXObject对象来实现在IE浏览器中上传文件的功能。
AJAX是一种用于在不重新加载整个网页的情况下从服务器异步传输数据的技术。它允许我们通过JavaScript与服务器进行通信,并在网页上实现动态更新。然而,在使用AJAX时,我们可能遇到跨域问题。跨域是指在浏览器中,
当涉及与跨域请求相关的Ajax开发时,我们通常会选择使用POST方法。然而,有时我们会不得不面对无法使用POST方法发送Ajax请求的情况。本文将会深入探讨造成这种限制的原因,并提供一些常见且解决此问题的方法。
Python是一种常用的编程语言,它可以用来开发各种各样的应用程序。其中,猜数字游戏算得分是Python初学者非常适合的练习项目之一。
AJAX(Asynchronous JavaScript and XML)指的是一种在客户端和服务器之间进行异步数据交互的技术,它可以在不影响页面加载速度的情况下,实现与服务器的数据交互,并动态更新页面内容。通过AJAX,用户可以在不刷新整
AJAX 是一种用于在后台与服务器进行异步通信的技术。它能够实现在不刷新整个页面的情况下,通过后台发送请求并将响应返回到前端。然而,有时候在使用 AJAX 上传文件时会出现错误 7。本文将探讨这个错误的原因,并提
在现代网页开发中,Ajax 技术的应用日益广泛。其中,Ajax 下拉菜单 slide(下拉菜单的滑动效果)是一种常见且有趣的交互方式。通过使用 Ajax 技术实现下拉菜单 slide,可以为用户提供更好的用户体验,同时也能增加网
AJAX(Asynchronous JavaScript and XML)是一种常用的Web开发技术,它通过异步通信方式实现了与服务器的数据交互。在AJAX中,我们可以使用HTTP协议发送请求到服务器并获取响应。然而,有时候我们需要在请求中传递一
Python是一门非常流行的编程语言,近年来它的受欢迎度一直在不断地提高。在Python的使用者中还有一位特别的粉丝,他就是我们的歌手王力宏。
在前端开发中,使用Ajax来进行文件下载是一种常见的方法。通过Ajax可以实现在不刷新整个页面的前提下,向服务器发送请求并接收返回的文件数据。然而,当文件较大或者下载过程比较耗时时,我们可能需要提供一些提示或