javascript - allow form action post submission after ajax call sucess in php jquery -


<form id="formid" method="post" action="#">  </form>  <script>  $(document).ready(function () {         $("#formid").submit(function (event) {              alert("handler .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 form have table dynamic data , validation using foreach. 1 single input validation used ajax call - if ajax call success, form needs submit. query insertion written in same page. can know how solve it? preventing default working, removing default event in ajax success call not working?

how solve?

because ajax-call asynchronous have prevent first form submit , when it's validated true make new form submit. haven't tried should work (notice lock variable introduced):

<script>  $(document).ready(function () {         var lock = false;         $("#formid").submit(function (event) {             if(!lock) {                 alert("handler .submit() called.");                 var driverpassword = $("#txtdriverpassword").val();                 var driverid = $("#driverid").val();                  $.ajax({                     type: "get",                     url: "page.php",                     data: {"data": data, "data1": dataaa, "method": "verifypassword"},                     success: function (result) {                          if (result === "valid") {                             // alert('valid credentials....');                             $("#formid").submit();                         }                         else {                             alert("invalid credentials");                          }                         lock = true;                     },                     error: function (xmlhttprequest, textstatus, errorthrown) {                         //  alert("status: " + textstatus); alert("error: " + errorthrown);                          $("#successmessage").html(textstatus);                     }                 });                 event.preventdefault();             }         });     }); <script> 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -