JQuery: waiting for a response from



  • Good afternoon. That's the code. https://jsfiddle.net/bst604jz/5/ It's a simplified version of my worker. The essence is simple. formValidate performs a form validation before shipment. There's a routine check on empty fields. But there is also a need to request a server that returns or returns OK or FAIL. If the answer OK, the form can be sent. If FAIL is not a form of sabmitism and a mistake. Call this code.

    formValidate(clb);
      if(valid) {
        console.log('1');
      };
    return false;
    

    clb performed, but checked valid returns false And only after that, it becomes true. And with the second sabmite of shape, it'll work as necessary. The question is, in fact, how do you make it possible to wait for a response from getting a request and only then check the condition?



  • form.submit(); - does not cause the processor to submit the event by jQuery.

    //check
    $('#mform').on('submit', function() {
      var form = this;
      formValidate(callback);
      return false;
    

    function callback(result) {
    if(!result) {
    alert('Капча невалидна');
    } else {
    form.submit();
    }
    }
    });




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2