<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form class="form-ajax" action="">
<input type="text" name="a" />
<input type="text" name="b" />
<textarea name="c" cols="30" rows="10"></textarea>
<input type="submit" value="Send" />
</form>
<p class="msg"></p>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script>
$('.form-ajax').submit(function(event) {
event.preventDefault();
var isValue;
$(this).children().not('[type=submit]').each(function() {
if ( $(this).val() == '' ) {
$('.msg').text('Заполните все поля');
isValue = false;
return false;
} else {
$('.msg').text('Все ок');
isValue = true;
}
});
if (isValue) {
$.ajax({
url: "/index.php?action=test",
method: 'POST',
type: 'POST',
data: $('.form-ajax').serialize(),
success: function (data) {
}
});
}
});
</script>
</body>
</html>