we can use javascript to validate form fields before submitting.
This method will not refresh the page.therefore No need to use Ajax.

HTML Code :

</code>

<html>
<head>
<script type="text/javascript">
function validate(){

var Name = document.getElementById('txtName');
if(Name.getAttribute('required') == '1' && Name.value == ''){
document.getElementById('errorMsg').innerHTML = "Please Fill Data";
document.getElementById('errorMessage').style.display= "";
return false;
}
else{
return true;
}

}

</script>
</head>
<title></title>
<body>
<form id="frmTest" action="test.php" method="POST" onSubmit="return validate();">
<table width="85%" align="centre"  id="tblTest" name="tblTest">

<div style="display:none" id="errorMessage">
<font color="red">
<p id="errorMsg">
</p>
</font>
</div>

<tr><td>Name : *</td><td><input type="text" id="txtName" name="txtName" required="1"></td></tr>
<tr><td>Age :</td><td><input type="text" id="txtAge" name="txtAge" required="0"></td></tr>
<tr><td><input type="submit" value="Submit"></td></tr>
</table>
</form>

</body>
</html>

<code>