March 2018
Intermediate to advanced
592 pages
13h 44m
English
Now the first thing we're going to change is going to be the form submit listener. In socket.emit we fetch the value from the field, and that's what we pass along. What we want to do next inside of the acknowledgment callback is clear the value. Once the request has been received by the server there's no reason to keep it around, so what we can do is add the same jQuery selector, targeting the field where the name attribute equals message. We're going to go ahead and clear its value by calling val once again, but instead of getting a value by providing no arguments, we're going to set the value to an empty string by passing in an empty string as the first argument:
jQuery('#message-form').on('submit', function ...