0

I am trying to use ajaxForm(options) to execute some methods before submitting the form.

Below are the options that I have set:

var options = {
                target : '#output1',
                success : showJsonResponse,
                beforeSubmit : validateFieldNotEmptyCallLoc,
                dataType : 'json'
            };

$('#formId').ajaxForm(options);

Regardless of what beforeSubmit returns ; true or false, success method -> showJsonResponse is called. Some article said "success " is replaced by "done" since jquery 1.8. Tried that doesn't like that "done" thing either

Edit 1

<input id="btn-font" type="submit" onclick="return callAjaxSubmitFunction();">

onclick function makes the $("#formId").submit();

JavaQuest
  • 671
  • 6
  • 23
  • and the url? where you place it? –  Jan 31 '17 at 16:21
  • 1
    what does "done" have to do with the plugin you are using? "ajax" and "ajaxForm" are two completely different things. – Kevin B Jan 31 '17 at 16:22
  • @Leandro it's on the form, theoretically – Kevin B Jan 31 '17 at 16:23
  • 1
    http://malsup.com/jquery/form/#validation i can't recreate your problem. – Kevin B Jan 31 '17 at 16:24
  • Most likely your validate callback is wrong. – Kevin B Jan 31 '17 at 16:27
  • @kevin the validate callback returns true or false – JavaQuest Jan 31 '17 at 16:30
  • @JavaQuest prove it. My expectation is that this question is a duplicate of http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – Kevin B Jan 31 '17 at 16:30
  • @KevinB you were absolutely correct. I messed up the validate callback function, it wasn't returning false; so never stopped the form from being submitted. Relatively new to javascript, used to java which gives compilation error right away if I miss return in non-void function – JavaQuest Jan 31 '17 at 19:20

1 Answers1

1

Made a stupid mistake of not returning the false in my beforeSubmit callback function. So it never stopped the form from being submitted. Thanks to @kevinB !

JavaQuest
  • 671
  • 6
  • 23