0

I have a form. I would like to execute my AJAX call on form submit, and only after its execution continue form submiting.

Here is the code example:

$('myform').observe('submit', function(e) {
    e.stop();
    new Ajax.Request('/myurl', {
        method:'get',
        onComplete: function(transport) {
            //Here I would like to continue form submitting
        },
    });
});
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
freento
  • 2,939
  • 4
  • 29
  • 53
  • Then the ajax would be called again... and again. – Simon Aug 07 '13 at 16:37
  • Yes, e.target.submit() doesn't work – freento Aug 07 '13 at 16:40
  • Well I know of a jQuery solution to this by using [.one()](http://api.jquery.com/one/) and actually submitting the form on ajax success. Like this the event listener would only fire the first time. I don't know prototype but maybe you find an equivalent to .one(). – Simon Aug 07 '13 at 16:42
  • See http://stackoverflow.com/questions/17999850/make-a-post-before-form-action-takes-place/17999931#17999931 – Christopher Marshall Aug 07 '13 at 17:06
  • @Bergi Sorry, you was right! e.target.submit() works! It didnot work in my case, because I has button with name="submit" in form, and this cause conflict, described here http://stackoverflow.com/questions/12540953/property-submit-of-object-htmlformelement-is-not-a-function – freento Aug 07 '13 at 17:57

0 Answers0