current position:Home>If the front-end does real-time data acquisition?

If the front-end does real-time data acquisition?

2022-05-15 02:02:53rojie0

If you do real-time data acquisition ?

//websocket agreement 
//  This is a socket The address of the interface 
var  wsServer = 'ws://localhost:8888/Demo' 

//  newly build socket object 
 var  websocket = new WebSocket(wsServer)

//  adopt onmessage event , Once the back-end interface data is updated , Then it will be transmitted to the client in real time .
 websocket.onmessage = function (evt) {
    
	//evt It contains the latest data 
 }

Follow http The protocol difference is that the link is continuous after request , As long as the data is updated , It will be transmitted to the client in real time .

Through the timer ajax Call interface .

setInterval(function(){
    
	// ajax call 
}, 1000)
 Equivalent to updating data every second 

copyright notice
author[rojie0],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/132/202205120528099375.html

Random recommended