JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<input type="text" name="polje1">
<input type="text" name="polje2">
</form>
<button id="send">Pošlji</button>
JavaScript
$("input:radio").attr("checked", false);
$('#send').click(function (event) {
event.preventDefault();
var isok = 0;
$('form input').each(function () {
if ($(this).val().length == 0) {
isok = 1;
$(this).focus();
return false;
}
});
if(isok == 0) {
$('<img src="ajax-loader.gif" class="ajaxLoader"/>').insertAfter("form");
var str = $('form').serializeArray();
$.ajax({
type: "POST",
url: "/insert.php",
data: str,
success: function () {
window.location.reload();
}
});
} else {
alert('Polje ni izpoljneno!\n');
}
});