javascript - Send two forms with ajax one submit button -



javascript - Send two forms with ajax one submit button -

i have tho forms on 1 page (one generated 1 service cant alter it). need when sumbit form1 firstly send ajax sec form after send sec form send first form. seek way:

$('#form1').submit(function(event) { var = (this); event.preventdefault(); $.ajax({ type:"post", url: "/wp-admin/admin-ajax.php", data: $('#form2').serialize(), success:function(data){ this.unbind('submit').submit(); } }); });

the problem is, cant send first form after sec one. ajax ends width success, first form not send.

thanks help

two things :

$.ajax() returns promise, can chain .then(fn), can create life easier regard meaning of this. form.submit() not retrigger form's submit handler, hence don't need unbind it.

try :

$('#form1').on('submit', function(event) { event.preventdefault(); $.ajax({ type: "post", url: "/wp-admin/admin-ajax.php", data: $('#form2').serialize() }).then(this.submit.bind(this)); });

javascript jquery ajax forms

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -