SocketIO Refreshing Page when Emitting

Whenever I emit something on SocketIO, it just reloads the page. Here’s the repl link:

1 Like

Tested it, and that’s happening to me too. I forked so I can use dev tools, there are no errors. I tried changing your code, now you don’t refresh…

      chatForm.addEventListener("submit", (event) => {
        content.value = chatInput.value
        socket.emit("msg", content)

      socket.on("msg", (res) => {
        const msgElem = document.createElement("p")
        msgElem.innerHTML = res.value

and it works.

Edit: changed the code more so you don’t alert twice.


Ahh. I should remember to not skip steps in tutorials.

You don’t need to fork to use dev tools, you can use your browser’s dev tools.

1 Like

My school/policies blocked that. It was because of people using inspect element.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.