使用Web套接字JavaScript更新表
我已经为此工作了一段时间了,但我一直未能实现我真正想要的。
我有一个表,我希望某些列能够根据 Websocket 的实时响应自动更改。
我有一个车辆列表,我希望在驾驶员移动时更新经度和纬度,我通过 websocket 获取实时信息,并且我想在车辆移动时更新表格。
这是我尝试过的
let ws = new WebSocket('ws://**.**.***.***:****');
var element = document.getElementById("div");
var tag = document.createElement("p");
ws.addEventListener("open", () => {
ws.send(JSON.stringify({
"ClientID": "1",
"UserID": "**************",
"UType": "1",
}));
});
ws.addEventListener("message", ({
data
}) => {
var data = JSON.parse(data);
const Lon = data.Lng;
const Lat = data.Lat;
document.getElementById("td").innerHTML = Lon;
});
i have been working on this for some time now, but i have not been able to achieve what i really want.
I have a table and I will like some column to change automatically based on the response from a websocket in real time.
I have a list of vehicle and I want the Longitude and latitude to update as the driver is moving, I fetching the realtime information via websocket, and I will like to update the table as the vehicle is moving.
This is what I have tried
let ws = new WebSocket('ws://**.**.***.***:****');
var element = document.getElementById("div");
var tag = document.createElement("p");
ws.addEventListener("open", () => {
ws.send(JSON.stringify({
"ClientID": "1",
"UserID": "**************",
"UType": "1",
}));
});
ws.addEventListener("message", ({
data
}) => {
var data = JSON.parse(data);
const Lon = data.Lng;
const Lat = data.Lat;
document.getElementById("td").innerHTML = Lon;
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论