JSFiddle - React, Tailwind, and code Playground
by ProjectSoft
HTML
<form id="anmessega" method="POST" action="" >
<div class="name text-input">
<label>Name</label>
<div class="error-mark">*</div>
<input type="text" maxlength="50" name="name">
</div>
<div class="message text-input">
<label>Message</label>
<div class="error-mark">*</div>
<textarea type="text" name="msg"></textarea>
</div>
<input type="submit" id="btntoogler" class="submit" value="Отправить">
</form>
JavaScript
var form = document.getElementById("anmessega"),
method = form.getAttribute("method"),
action = form.getAttribute("action"),
xhr;
form.onsubmit = function(e){
e.preventDefault();
xhr && xhr.abort();
var formData = new FormData(form)
xhr = new XMLHttpRequest();
xhr.open(method, action, true);
xhr.send(formData);
form.reset();
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;
if(xhr.status != 200){
alert(xhr.status+" Ошибка")
}else{
alert(xhr.status+" Отправлено")
}
}
return !1;
}