<form id="formModel" enctype="multipart/form-data">
<input type="text" name="title" required>
<input type="text" name="meta_t" required>
<input type="text" name="text">
<input type="file" name="imgurl">
<button type="submit" name="submit" id="btnSubmit">Создать</button>
</div>
</form>
$("#formModel").submit(function() {
$.ajax({
url: 'control',
method: "POST",
data: new FormData( this ),
success: function(data) {
$("#formModel input[name='title']").val(''),
$("#formModel input[name='meta_t']").val(''),
$("#btnSubmit").attr("value", "Отправлено")
}
});
return false;
});
<form onsubmit="submitForm(event)" action="control" method="POST" id="formModel" name="nameformModel" enctype="multipart/form-data">
<input type="text" name="title" required>
<input type="text" name="meta_t" required>
<input type="text" name="text">
<input type="file" name="imgurl">
<button type="submit" name="submit" id="btnSubmit">Создать</button>
</div>
</form>
function submitForm(event){
event.preventDefault();
event.stopPropagation();
let form = document.forms.nameformModel;
let url = form.action;
let data = new FormData(form )
var akaxOptions = { method: 'POST',
mode: 'cors',
credentials: 'include',
body:data
};
fetch(form.action,akaxOptions ).then(function(response){
return response.json();
}).then(function(json){
form.reset();
form.submit.value= "Отправлено";
})
}