Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
Getting errors while trying to log inputs from a form
const socket = io('https://localhost:3000')
const messageForm = document.getElementById('send-container')
const messageInput = document.getElementById('message-input')

socket.on('chat-message', data =>{
console.log(data)

}
)

messageForm.addEventListener('submit', e => {
e.preventDefault()
const message = messageInput.value
socket.emit('send-chat-message', message)
messageInput.value = ''
})

    <script defer src="http://localhost:3000/socket.io/socket.io.js"></script>
<script defer src="chatscript.js"></script>

<div id="message-container"></div>
    <form id='send-container'>
        <input type="text" id="message-input"></input>
        <button type="submit" id="send-button">send</button>
    </form>

When a user enters a submits a message in the input tag, the message should be logged into the console. But instead, i'm getting

Loading failed for the <script> with source “http://localhost:3000/socket.io/socket.io.js”.
 file:///C:/Users/myname/Desktop/AvackGames/AvackGames/chatscript.js:1

Errors on Firefox and errors on Chrome.

GET http://localhost:3000/socket.io/socket.io.js net::ERR_CONNECTION_REFUSED avackchat.html:9
chatscript.js:1 Uncaught ReferenceError: io is not defined
    at chatscript.js:1:16

I've tried running "npm install cors" but it hasn't fixed the issue.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda