Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Javascript socket display new pushed data every k seconds

I am new to JavaScript and I am trying to display list of messages pushed by websocket every K seconds. I am able to received data from the websocket and can view it using console.log

<html lang="EN">
<head>

    <script type="text/javascript">
        function myFunction() {

            if ("WebSocket" in window) {
                const ws = new WebSocket("ws://localhost:9000/test");
                ws.onopen = function () {
                    console.log("connection opened");
                };
                ws.onmessage = function (evt) {
                    const data = evt.data;
                    console.log(data)
                };

              
            } 
        }
    </script>
    <title></title>

</head>

<body>
<div id="sse">
    <a href="javascript:myFunction()">Start</a>
</div>

</body>
</html>

Now I am not sure how can I display the data that's pushed every K seconds as a list such that the new data is on the top and the list scrolls automatically?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!