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

前端之家收集整理的这篇文章主要介绍了pushlet简单例子ajax-pushlet-client.js前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<%@ 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> 原文链接:https://www.f2er.com/ajax/163517.html

猜你在找的Ajax相关文章