每隔15s异步刷新手机页面
前台异步js发请求代码:
<script type="text/javascript">
var lightArr;
var lightHistoryArr;
/* 每隔15s刷单灯列表 */
$(document).ready(function() {
setInterval(function() {
$.ajax({
type: "post",
url: "${ctx}/sys/light/refurbishLights",
contentType : "application/x-www-form-urlencoded; charset=UTF-8",
data: { books: "book", txtPass: "123"},
success: function (res) {
lightHistoryArr=lightArr;
lightArr=res;
lightArr=eval("("+lightArr+")");
console.log(lightArr);
var htmlDiv="<div class='indented' style='transition-property: transform; transform-origin: 0px 0px 0px; transform: translate(0px, 0px) translateZ(0px);'><div></div></div>"; for(var i=0;i<lightArr.length;i++){
for(key in lightArr[i]){
//加载变化的路灯
if(lightArr[i][key]!=lightHistoryArr[i][key]){
}
}
var inti=parseInt(i) + 1;
if(inti%2==0){
htmlDiv+="<li data-icon='next' data-selected='selected' style='background-color:#eefaff;'>";
}
if(inti%2!=0){
htmlDiv+="<li data-icon='next' data-selected='selected' style='background-color:#FFFFFF;'>";
}
htmlDiv+="<i class='icon next'></i>";
htmlDiv+="<a href='#light_section?lightGuid="+lightArr[i].lightGuid+"' data-target='section'></a>";
htmlDiv+="<div class='grid'>";
htmlDiv+="<div class='col-1' >";
if(lightArr[i].icon==0){
htmlDiv+="<img alt='dad' src='${pageContext.request.contextPath}/static/images/-hong@2x.png' width='24px' height='24px'>";
}
if(lightArr[i].icon==1){
htmlDiv+="<img alt='dad' src='${ctxStatic}/images/-lv@2x.png' width='24px' height='24px'>";
}
htmlDiv+="<span style='font-family: PingFangSC-Regular;font-size: 16px;color: #333333;letter-spacing: 0;display: inline-block;vertical-align: middle;'>"+lightArr[i].title+"</span></div>";
if(inti%2!=0){
htmlDiv+="<div class='label' style='background-color:FFFFFF;'>";
}
if(inti%2==0){
htmlDiv+="<div class='label' style='background-color:#eefaff;background:#eefaff;'>";
}
if(lightArr[i].icon==0){
htmlDiv+="<span style='background: #FFFFFF;border: 1px solid #666666;border-radius: 4px;color: #666666;padding: 3px 8px;'>已关灯</span>";
}
if(lightArr[i].icon==1){
htmlDiv+="<span style='background: #FFFFFF;border: 1px solid #16c4af;border-radius: 4px;color: #16c4af;padding: 3px 8px;'>已开灯</span>";
}
htmlDiv+="</div></div></li>";
htmlDiv+=""; }
$(".list").html(htmlDiv);
}
})
}, 15000);//15s刷新
});
</script> 后台java代码:
@ResponseBody
@RequiresPermissions("sys:light:view")
@RequestMapping(value = {"refurbishLights", "12"})
public String refurbishLights(Light light, HttpServletRequest request, HttpServletResponse response, Model model) { try {
org.tempuri.TLight[] lights = phlightSoapProxy.getLights();
org.tempuri.TRoad[] tRoads = phlightSoapProxy.getRoads();
org.tempuri.TAlarm[] tAlarms = phlightSoapProxy.getNewAlarms();
String jsonStr = null;
JSONArray array = new JSONArray();
/* Json格式的数组形式 */
JSONObject obj;
/* json格式的单个对象形式 */
for (int i = 0; i < lights.length; i++ )
{
obj = new JSONObject();
obj.put( "lightGuid", lights[i].getLightGuid() );
obj.put( "title", lights[i].getLightName() );
/* json通过put方式以key-value形式填充 */
obj.put( "icon", lights[i].getYxValue() == 0 ? 0 : 1 );
String state = lights[i].getYxValue() == 0 ? "已关灯" : "已开灯";
obj.put("index","ddzt");
array.put(obj);
/* 将JSONObject添加入JSONArray */
}
model.addAttribute("index", "ddzt");
model.addAttribute( "lights", lights );
model.addAttribute( "lightsJSON", array.toString());
System.out.println(array.toString());
return array.toString();
}catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "success";
}
前台jsp代码:
<article class="active" id="layout_book_article" style="top:81px;" data-scroll="true"> <ul class="list" style="transition-property: transform; transform-origin: 0px 0px 0px; transform: translate(0px, -38px) scale(1) translateZ(0px);">
<div class="indented"
style="transition-property: transform; transform-origin: 0px 0px 0px; transform: translate(0px, 0px) translateZ(0px);">
<div></div>
</div>
<c:forEach items="${lights}" var="light" varStatus="index"> <li data-icon="next" data-selected="selected" <c:if test="${(index.index+1)%2 == 0}">style="background-color:#eefaff;"</c:if><c:if test="${(index.index+1)%2 != 0}">style="background-color:#FFFFFF;"</c:if>>
<i class="icon next"></i>
<a href="#light_section?lightGuid=${light.lightGuid}" data-target="section"></a>
<div class="grid">
<div class="col-1" >
<c:if test="${light.yxValue eq 0}"><img alt="dad" src="${pageContext.request.contextPath}/static/images/-hong@2x.png" width="24px" height="24px"></c:if>
<c:if test="${light.yxValue eq 1}"><img alt="dad" src="${ctxStatic}/images/-lv@2x.png" width="24px" height="24px"></c:if>
<span style="font-family: PingFangSC-Regular;font-size: 16px;color: #333333;letter-spacing: 0;display: inline-block;vertical-align: middle;">${light.lightName}</span>
</div>
<div class="label" <c:if test="${(index.index+1)%2 != 0}">style="background-color:FFFFFF;"</c:if><c:if test="${(index.index+1)%2 == 0}">style="background-color:#eefaff;background:#eefaff;"</c:if> >
<c:if test="${light.yxValue eq 0}"><span style="background: #FFFFFF;border: 1px solid #666666;border-radius: 4px;color: #666666;padding: 3px 8px;">已关灯</span></c:if>
<c:if test="${light.yxValue eq 1}"><span style="background: #FFFFFF;border: 1px solid #16c4af;border-radius: 4px;color: #16c4af;padding: 3px 8px;">已开灯</span></c:if>
</div>
</div>
</li>
</c:forEach>
</ul>
</article>
手机自动刷起来:![]()
每隔15s异步刷新手机页面的更多相关文章
- 纯css3手机页面图标样式代码
全部图标:http://hovertree.com/texiao/css/19/ 先看效果: 或者点这里:http://hovertree.com/texiao/css/19/hoverkico.ht ...
- 禁止手机页面中A标签长按弹出路径框
//禁止手机页面中A标签长按弹出路径框 window.onload=function(){ document.documentElement.style.webkitTouchCa ...
- JS 模拟手机页面文件的下拉刷新
js 模拟手机页面文件的下拉刷新初探 老总说需要这个功能,好吧那就看看相关的东西呗 最后弄出了一个简单的下拉刷新页面的形式,还不算太复杂 查看 demo 要在仿真器下才能看到效果,比如chrome的里 ...
- 手机页面中的meta标签
以前看书的时候,觉得meta标签就只有一个charset对于我来说是有用的.前段时间有个学弟让我写个手机版的网页,我才知道原来meta标签有那么多学问. meta指元素可提供有关页面的元信息(meta ...
- Ajax异步刷新局部页面的小李子
看到下面那幅图没有,我们要的是当点击确定以后,根据条形码搜索出商品信息,并且异步刷新右边页面:
- 使用fiddler4做代理调试手机页面
由于一般手机不能改host,手机页面如果涉及到各个域名ip的混合使用,在手机上调试看效果非常麻烦. 使用fiddler4做代理,手机跟电脑连到同一个局域网,手机上网通过电脑做个代理上网,那么一切请求就 ...
- 手机页面rem布局
手机页面设计一般的大小是640,但是,手机屏幕大小确实不确定的,这样,怎么才能做出适应所有手机的手机页面呢?一般的解决方案有两种,rem布局和百分比布局,更推荐用rem布局来制作手机页面. 首先,给页 ...
- html禁止手机页面放大缩小
html禁止手机页面放大缩小 <meta name="viewport" content="width=device-width,minimum-scale=1.0 ...
- UC浏览器开发者版调试手机页面
1 关于RI 目前,在手机上使用浏览器访问网页,无法便捷地进行网页语言调试.手机屏幕相对较小且操作不便,直接在手机上进行网页数据调试不太现实. 因此,我们使用技术将手机网页调试信息分离,实现一种能在大 ...
随机推荐
- scrapy中间件中发送邮件
背景介绍:之前写过通过通过scrapy的扩展发送邮件,在爬虫关闭的时候发送邮件.那个时候有个问题就是MailSender对象需要return出去.这次需要在中间件中发送邮件,但是中间件中不能随便使用r ...
- [转帖]systemd 开机无法启动privoxy
systemd 开机无法启动privoxy https://www.cnblogs.com/liuxuzzz/p/5329536.html 此博客不在更新,我的博客新地址:www.liuquanhao ...
- FPGA控制RGMII接口PHY芯片基础
一.前言 网络通信中的PHY芯片接口种类有很多,之前接触过GMII接口的PHY芯片RTL8211EG.但GMII接口数量较多,本文使用RGMII接口的88E1512搭建网络通信系统.这类接口总线位宽小 ...
- 『磁力块 bfs 分块』
磁力块 Description 在一片广袤无垠的原野上,散落着N 块磁石.每个磁石的性质可以用一个五元组 (x,y,m,p,r)描述,其中x,y 表示其坐标,m 是磁石的质量,p 是磁力,r 是吸引半 ...
- mysql 事务的实现原理
开篇 相信大家都用过事务以及了解他的特点,如原子性(Atomicity),一致性(Consistency),隔离型(Isolation)以及持久性(Durability)等.今天想跟大家一起研究下事务 ...
- lazyload的使用方法
http://blog.csdn.net/peidandan/article/details/8107634
- mvc中hangfire全局简单配置
public void Configuration(IAppBuilder app) { ConfigureAuth(app); //指定使用Sql ...
- 我碰到的stackoverflow error
出现这种问题,首先需要检查自己的代码: 要么代码小错误:或者逻辑错误: 如果出现循环调用更要仔细检查: 我的问题: 循环调用:一个实体他有自己的父栏目,含有子栏目的list集合:两者结果映射resul ...
- mybatis关联映射一对多
实际项目中也存在很多的一对多的情况,下面看看这个简单的例子 table.sql CREATE TABLE tb_clazz( id INT PRIMARY KEY AUTO_INCREMENT, CO ...
- android的子线程切换到主线程
在子线程中,如果想更新UI,必须切换到主线程,方法如下: if (Looper.myLooper() != Looper.getMainLooper()) { // If we finish mark ...