加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

pushlet简单例子ajax-pushlet-client.js

发布时间:2020-12-16 02:02:34 所属栏目:百科 来源:网络整理
导读:%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% !DOCTYPE html % String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; % head titl
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE html> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <head> <title>消息推送模式与内容测试</title> <meta charset="UTF-8"> <link href="style.css" rel="stylesheet"> <meta http-equiv="Pragma" content="no-cache"> <script type="text/javascript" src="<%=basePath %>js/pushlet_js/ajax-pushlet-client.js"></script> <script type="text/javascript"> var tempTrureId = ''; var stockId = ''; function onEvent(event){ document.getElementById("info").innerHTML=event.toString(); if(event.get('p_subject')=='/temperature'){ tempTrureId = event.get("p_sid"); displayTemptrueData(event.toString()); }else if(event.get('p_subject')=='/stocks/aex'){ stockId = event.get("p_sid"); displayStocksData(event.toString()); } } function displayTemptrueData(aString) { document.getElementById("displayTemptrue").value=aString; } function displayStocksData(aString) { document.getElementById("displayStocks").value=aString; } function listemTemptrue(){ PL._init(); PL.joinListen("/temperature"); } function unsubscribeTemptrue(){ PL.unsubscribe(tempTrureId); displayTemptrueData(''); } function listemStock(){ PL._init(); PL.joinListen("/stocks"); } function unsubscribeStock(){ PL.unsubscribe(stockId); displayStocksData(""); } function leave(){ PL.unsubscribe(); PL.leave(); } </script> </head> <body> <br></body> <article> <header> <h1>pushlet例子</h1> </header> </article> <article> <form> 事件显示:<textarea rows="10" cols="30" id=displayTemptrue></textarea> 天气显示:<textarea rows="10" cols="30" id=displayStocks></textarea> <input type="button" value="监听天气" onclick="listemTemptrue();"/> <input type="button" value="取消监听天气" onclick="unsubscribeTemptrue();"/> <input type="button" value="监听股票" onclick="listemStock();"/> <input type="button" value="取消监听股票" onclick="unsubscribeStock()"/> <input type="button" value="离开" onclick="leave()"/> <div id=info style="width:400px;height:200px;border:1px solid"></div> </form> </article> </html>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读