React generated button on my form keeps refreshing the page. Sounds to me like a delegation issue – I’ll bet #chat isn’t in the DOM when you are creating the submit handler.
Try delegating the submit to the document (and preventing the default action):
1 2 3 4 | $(document).on('submit','#chat',function(e) { e.preventDefault(); ... }); |
Here is another example:
1 2 3 4 5 6 7 8 9 10 11 12 | handleSubmit(event) { alert('A name was submitted: ' + this.state.value); **event.preventDefault();** } <form onSubmit={**this.handleSubmit**}> <label> Name: <input type="text" value={this.state.value} onChange={this.handleChange} /> </label> <input type="submit" value="Submit" /> </form> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.