使用ajax与iframe嵌套实现页面局部刷新
使用ajax与iframe嵌套实现页面局部刷新。该javascript代码仅供参考,需按自己需要修改。
1. [代码]javascript代码
function cj_start(depname,groupid){
var urls = "<%=path%>/userGather.action";
var status = "";
var html_1 = "<iframe frameborder=\"0\" scrolling=\"no\" width=\"600\" height=\"60\" src=\"<%=basePath%>cj_status.jsp\" style=\"margin-top:3px;vertical-align: middle;\"></iframe>";
$("#cj_status_html").html(html_1);
var html_2 = "";
var cj_butoon = "";
$.ajax({
url : urls,
type:"post",
dataType:"json",
data:{depname:depname,groupid:groupid},
success : function(data){
if(data.cjstatus.length != 0){
if(data.cjstatus[0] == "0"){
cj_button = "<input type=\"button\" value=\"采集通道\" disabled=\"disabled\"/>";
$("#cj_button_html").html(cj_button);
}
for(var i = 1; i < data.cjstatus.length; i++){
html_2 += data.cjstatus[i] + " ";
}
$("#cj_status_html").html(html_2);
}else{
html_2 = "采集系统出错,请联系开发人员!";
$("#cj_status_html").html(html_2);
}
}
});
}
2. [代码]jsp的部分代码
<tr>
<td id="cj_button_html">
<input type="button" name="caiji" value="采集通道" onclick="cj_start('<%=depname %>','<%=groupid %>');"/>
</td>
</tr>
<tr>
<td id="cj_status_html">
</td>
</tr>
3. [代码]cj_status.jsp的代码
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%http://www.bizhizu.cn/manhua/
String path = request.getContextPath();漫画图片
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
</head>
<body>
<div>
<img src="<%=basePath %>images/loading_16x16.gif" /> <span>正在采集数据,请稍后...</span>
</div>
<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>
</body>
</html>