Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add document.ready() to the tutorial html and website #8

Open
xShirase opened this issue Oct 8, 2014 · 5 comments
Open

add document.ready() to the tutorial html and website #8

xShirase opened this issue Oct 8, 2014 · 5 comments

Comments

@xShirase
Copy link

xShirase commented Oct 8, 2014

I came by this question today on SO :

http://stackoverflow.com/questions/26261059/socket-io-chat-tutorial-not-functioning-properly

We need to add document.ready to the tuto for it to work, and update the Socket.IO website too so the newbies don't panic :)

$( document ).ready(function() {
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
});

@xShirase xShirase changed the title add document.ready() to the tutorial html add document.ready() to the tutorial html and website Oct 8, 2014
@HoverBaum
Copy link

Was going to point out the same thing. In the tutorial it tells us to put the script in the head. But that results on the handler not properly being added.

I would suggest updating the tutorial on http://socket.io/get-started/chat/ to put the script at the end of the body like the file on Git does.

@glaukommatos
Copy link

I've also run into this issue while implementing the example application. While I'm familiar with the $(document).ready(...) pattern, I assumed I was doing something else wrong or that my browser was being weird, since I didn't trust my own JavaScript knowledge more than I trusted the Socket.IO example.

I definitely agree that it's a good idea to update the tutorial, since I know that if I hadn't already been familiar with the problem, I would have spent a very long time trying to figure it out and been very discouraged instead of coming to Github to whine about it. 👍

Let me know if I can help, thanks!

@ilkermutlu
Copy link

It does already work without $(document).ready();, at least on my part.

@ABtasty-Li-Liuyi
Copy link

Reference ==> I have the same problem of $(document).ready();. I thought the socket.io is not working, I checked a lot of times, then I found even the submite event is not triggered. So $(document).ready(); is necessary for me.

@VaelVictus
Copy link

I put it in the header, as I should, and it didn't work. Document ready did it. $(function(){}), of course.

TheSachinSBhat added a commit to TheSachinSBhat/chat-example-1 that referenced this issue Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants