Update table with web socket javascript

Viewed 215

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;
    });
0 Answers
Related