Skip to content
Advertisement

How can I make a simple chat/store messages in localhost?

I’m working on exercise, a simple chat/store messages, working on localhost, but it’s not working properly. The objective is to send user and message, and store the user and messages sent with a date. Like:(11:32 @USER: Hello world).

This message data (with user,message and date) should be displayed on page, one after another.

I’m doing this with no dependencies, but I cannot seem to make that work. I will post a feedle on it, can someone help me with this?

JavaScript
JavaScript

Advertisement

Answer

Since the button type is submit , on click the form submits and performs its default behavior ( send a get request – effectively refreshing the page ) . To prevent this you will have to accept to add e.preventDefault() in your event handler code .

JavaScript
JavaScript
Advertisement