Whenever I emit something on SocketIO, it just reloads the page. Here’s the repl link: https://replit.com/@OmegaOrbitals/Chat-App?s=app
Webview: https://chat-app.omegaorbitals.repl.co
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) => {
event.preventDefault();
content.value = chatInput.value
socket.emit("msg", content)
})
socket.on("msg", (res) => {
const msgElem = document.createElement("p")
msgElem.innerHTML = res.value
chatMsgs.append(msgElem)
})
and it works.
Edit: changed the code more so you don’t alert twice.
2 Likes
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.