<form id="formId" method="POST" action="#">
</form>
<script>
$(document).ready(function () {
$("#formId").submit(function (event) {
alert("Handler for .submit() called.");
var data= $("#txtDriverpassword").val();
var data1= $("#driverId").val();
$.ajax({
type: "GET",
url: "page.php",
data: {"data": data, "data1": data1, "method": "verifypassword"},
success: function (result) {
if (result === "valid") {
// alert('valid credentials....');
return true;
}
else {
alert("invalid credentials");
return false;
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// alert("Status: " + textStatus); alert("Error: " + errorThrown);
$("#successMessage").html(textStatus);
}
});
//event.preventDefault();
});
});
<script>
Inside the form I have a table with dynamic data and validation for it using foreach
. Now for one single input validation I just used an ajax call - if ajax call is a success, the form needs to submit. The query for insertion is written in the same page. can i know how to solve it? preventing default is working, but removing default event in the ajax success call is not working?
How to solve?