JSFiddle - React, Tailwind, and code Playground
HTML
<form action="#">
<textarea name="comment"></textarea>
</form>
<div id="log">
<p></p>
</div>
JavaScript
var log = document.getElementById("log");
$(function(){
$('textarea').keypress(function(e) {
if (e.keyCode == 13 && !e.shiftKey) {
e.preventDefault();
var frm = this.form; // don't submit the form yet
$.ajax({
url: $(frm).attr('action'), // remember to specify which attribute you want
data: $(frm).serialize(),
dataType: "json",
success: function() {
$("#log").append($("textarea").val());
// submit the form when the ajax request is complete
// frm.submit();
}
});
}
});
});