Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

EventSource push of H5

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

EventSource push (ajax normal polling)

Subscribe to if (window.EventSource) {var eventSource = new EventSource (""); eventSource.onmessage = function (e) {document.body [XSS _ clean] + = e.data +'

';}; / / whenever you connect to the server, the open event eventSource.addEventListener ("open", function () {console.log ("establishing a connection with the server"); / / processes the load event eventSource.addEventListener in the server response message ("load", function (e) {console.log ("data sent by the server to the client is" + e.data);}) / / if no event is specified in the server response message, the message event eventSource.addEventListener ("message", function (e) {console.log ("data sent by the server to the client is" + e.data);}) is triggered by default; / / if an error occurs, the error event eventSource.addEventListener ("error", function (e) {console.log ("data sent by the server to the client is" + e.data);}) is triggered) } else {console.log ("the server does not support EvenSource objects");} eventSource.addEventListener ("open", function () {console.log ("establish a connection with the server");}) / / process the load event eventSource.addEventListener in the server response message ("load", function (e) {console.log ("server load data is:" + e.data);}) / / if no event is specified in the server response message, the message event eventSource.addEventListener is triggered by default ("message", function (e) {console.log ("the data sent by the server to the client is:" + e.data);}) / / if an error occurs, the error event eventSource.addEventListener ("error", function (e) {console.log ("server error data is" + e.data);});} else {console.log ("the server does not support EvenSource objects");} / / var count = 0 / / var comet = new iComet ({/ / channel: 'ch2', / / subUrl:', / / callback: function (content, type) {/ / count + +; / / var output = document.getElementById ('output'); / / var time =''+ (new Date ()) / / output [XSS _ clean] + = count +'. '+ time +': ('+ type +')'+ content +'; / /} /})

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report