klasss Posted February 20, 2022 at 12:34 PM Report Share #625438 Posted February 20, 2022 at 12:34 PM Quando vou a consola no browser tenho esse erro : <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous" defer></script> <script src="https://cdn.socket.io/4.4.1/socket.io.min.js" integrity="sha384-fKnu0iswBIqkjxrhQCTZ7qlLHOFEgNkRmK2vaO/LbTZSXdJfAu6ewRBdwHPhBo/H" crossorigin="anonymous"></script> <script> $(function() { let ip_address = '127.0.0.1'; let socket_port = '3000'; let socket = io(ip_address + ':' + socket_port); let chatInput = $('#chatInput'); chatInput.keypress(function(e) { let message = $(this).html(); console.log(message); }) }); </script> O erro vem da seguinte linha <script> $(function() { Alguem sabe o motivo de este erro acontecer? Obrigado ! Link to comment Share on other sites More sharing options...
Solution Ivo Vicente Posted February 20, 2022 at 10:15 PM Solution Report Share #625441 Posted February 20, 2022 at 10:15 PM Viva, Estas a carregar a biblioteca com a opção defer o que faz com que só seja feito o seu download no fim da página indicar o estado ready Mas antes da pagina estar pronta estas a tentar usar o Jquery que ainda não está no sistema. Para resolver, remove esse atributo do tag script ficando <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"> Mais detalhes interessantes: https://www.w3schools.com/tags/att_script_defer.asp Feito é melhor que perfeito Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now