Ajax刷新DIV内容

实现了网页的异步数据处理,不用刷新整个页面

<标签 onmouseover="method"/ >
method:这个参数是处理onmouseover事件的方法。
<li onmouseover="startRequest('1')">简单</li>
<li onmouseover="startRequest('2')">面向对象</li>
<li onmouseover="startRequest('3')">可移植性</li>
<li onmouseover="startRequest('4')">分布性</li>
<li onmouseover="startRequest('5')">解释器通用性</li>
<li onmouseover="startRequest('6')">健壮</li>
<li onmouseover="startRequest('7')">多线程</li>
<li onmouseover="startRequest('8')">高性能</li>
标签对象.innerHTML=text
text:这个参数是替换标签内容的字符串。
var content=document.getElementById("content");
content.innerHTML=xmlhttp.responseText;
<script type="text/javascript">
void xmlhttp;
function createXmlHttpRequest(){ // 创建XMLHttpRequest请求对象
if(window.ActiveXObject){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
}
function changeDiv(){ // 处理DIV数据的方法
var content=document.getElementById("content");
content.innerHTML=xmlhttp.responseText;
}
function startRequest(str){ // 发送页面请求
createXmlHttpRequest();
xmlhttp.onreadystatechange=changeDiv;
xmlhttp.open("GET", "DivContentServlet?divStr="+str, true);
xmlhttp.send(null);
}
</script>
<table border="1">
<thead>
<tr>
<th>Java特性</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<ol type="1">
<li onmouseover="startRequest('1')">简单</li>
<li onmouseover="startRequest('2')">面向对象</li>
<li onmouseover="startRequest('3')">可移植性</li>
<li onmouseover="startRequest('4')">分布性</li>
<li onmouseover="startRequest('5')">解释器通用性</li>
<li onmouseover="startRequest('6')">健壮</li>
<li onmouseover="startRequest('7')">多线程</li>
<li onmouseover="startRequest('8')">高性能</li>
</ol>
</td>
<td width="280" height="200" valign="top">
<DIV ID="content"><!-- 这里将插入DIV内容 --></DIV>
</td>
</tr>
</tbody>
</table>
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8"); // 设置应答类型
JDBCDao dao = new JDBCDao(); // 创建数据库操作类
PrintWriter out = response.getWriter(); // 获取应答对象输出流
String divStr = request.getParameter("divStr"); // 获取请求参数
if (divStr == null || divStr.isEmpty()) {
divStr = "1";
}
int id = Integer.parseInt(divStr);
String info = dao.getInfo(id); // 从数据库获取参数对应的说明文字
out.print(info); // 把说明文字输出到浏览器
}
public String getInfo(int id) {
String content=null; // 内容文本
Statement stmt = null; // 创建Statement对象
ResultSet rs = null; // 创建结果集对象
Connection conn = getConn(); // 获取数据库连接对象
try {
// 定义查询数据库的SQL语句
String sql = "SELECT content FROM tb_javainfo where id="+id;
stmt = conn.createStatement();
rs = stmt.executeQuery(sql); // 执行数据库查询
if (rs.next()) {
content = rs.getString(1); // 获取说明文字
}
} catch (SQLException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} finally {
close(rs, stmt, conn); // 关闭并释放资源
}
return content;
}

Ajax刷新DIV内容的更多相关文章

  1. jQuery刷新div内容,并对刷新后元素绑定事件。$(document).on()

    给id=zt的元素绑定点击事件 点击刷新id=ps_list中类容(内容中含有id=zt元素) 把zt的点击事件委托到了document上,这样就不用考虑事件是否能绑定到新加元素上 代码如下: $(d ...

  2. 使用jquery实现局部刷新DIV

    实现页面的定时刷新功能:jquery使用的是jquery-1.8.3.min.js1:定时刷新 A界面的一段代码如下:<script type="text/javascript&quo ...

  3. jQuery 清除div内容

    $.ajax({            url: "SearchSN.aspx",            data: "SN=" + $("#txtS ...

  4. django-simple-captcha 验证码插件介绍 django-simple-captcha 使用 以及添加动态ajax刷新验证

    django-simple-captcha作为一款django的验证码插件,使用方法非常简单,能够快速应用到web应用中. 文档官网地址:django-simple-captcha 参考博客:http ...

  5. django-simple-captcha 使用 以及添加动态ajax刷新验证

    参考博客:http://blog.csdn.net/tanzuozhev/article/details/50458688?locationNum=2&fps=1 参考博客:http://bl ...

  6. jquery鼠标移动div内容上下左右滚动

    jquery鼠标移动div内容上下左右滚动 点击这里查看效果:http://keleyi.com/keleyi/phtml/jqtexiao/9.htm <!DOCTYPE html PUBLI ...

  7. jQuery div内容间隔1秒动态向上滚动HTML、JS代码

    demo1: <!DOCTYPE html> <html> <head> <title>div内容间隔1秒动态滚动</title> < ...

  8. jQuery 编辑div内容

    div显示如下 <div id="showResult"></div> div中添加的html,进行拼接 $("#showResult" ...

  9. 监听div内容改变

    做前端突击队,外星人那道是自己手动模拟那个时间的变化的,但正确思路应该是监听div内容的变化然后同步到输入框中,遂今天找了一下,结果如下: $('div').bind('DOMNodeInserted ...

随机推荐

  1. 十个推荐使用的 Laravel 的辅助函数

    壹. array_dot() array_dot () 辅助函数允许你将多维数组转换为使用点符号的一维数组. $array = [ 'user' => ['username' => 'so ...

  2. 【Git】git rebase报错new blank line at EOF.处理

    执行git rebase报错如下: First, rewinding head to replay your work on top of it... Applying: 本次提交信息 .git/re ...

  3. SQL语句完整的执行顺序(02)

    这是对SQL语句完整的执行顺序(01)的补充: 数据库是mysql,使用的数据库表名称是my_student. 表的完整数据信息是: 完整语法是: Select [select选项] 字段列表[字段别 ...

  4. listagg within group

    oracle 多行合并成一行: listagg within group 可以和递归方法一起使用查询路径: 例如: SELECT LISTAGG(t.FOLDER_NAME, '/') WITHIN ...

  5. JS & JQuery 动态处理select option

    原文 出处http://www.51xuediannao.com/html+css/htmlcssjq/cssbuhuanhang.html 今天你问了我一个关于在<select>里动态添 ...

  6. trie字典树:初学

    应用: 1.前缀问题 2.异或问题(转化为前缀问题) 3.查询问题 思想: 将要进行匹配的字符串化为一颗树 字符为边,在结束位置统计该串的全部信息 操作:插入,查询,删除.etc ac: #inclu ...

  7. java 异步线程下的顺序控制

    转载请注明出处!!!! java.util.concurrent.CountDownLatch 的使用可以达到效果   CountDownLatch是JAVA提供在java.util.concurre ...

  8. ***OneinStack交互安装FAQ和管理服务常用命令

    转自: https://oneinstack.com/install/  自动生成oneinstack安装连接: https://oneinstack.com/auto/ (进入linux系统后复杂上 ...

  9. thinkphp5简单使用redis缓存

    <?php namespace app\index\controller; use think\Controller; use think\Cache\Driver\Redis; class I ...

  10. POSIX-Data Structure

    struct sigevent The <signal.h> header shall define the sigeventstructure, which shall include ...