jquery : submitting a form twice

前端 未结 8 1010
抹茶落季
抹茶落季 2020-12-10 03:12

I\'m creating a registration form for a client for an event they\'re hosting. The basic user details are submitted to a third-party system (ie name, email etc.) but the rest

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 03:48

    Do you have a reason to have to utilize the submit-method? The reason it enter an infinite loop is because it invokes the same submit event listener again.

    If not, you can just queue two ajax-submits, one to the e-mail page, and again to the client.

    Finally, you can unbind the event listener. A little known way to unbind an event listener is to pass in the event object to the unbind-call. This will unbind only the current event listener:

    $('#form1').submit(function(e){
        if(myvalidator.isValid()){
    $form = $('#form1');
    $.ajax({
        data: $form.serialize(),
                   type: "POST",
                   url: "email_send.asp",
                   success: function(){
                     $form.unbind(e).submit();
                   }
                 });
        }
        return false;
    });
    

提交回复
热议问题