jquery : submitting a form twice

前端 未结 8 981
抹茶落季
抹茶落季 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:46

    try unbinding submit event on your success: method of your ajax call by calling unbind

    $('#form1').unbind('submit'); 
    $('#form1')[0].submit(); // call native submit
    

    http://api.jquery.com/unbind/

    0 讨论(0)
  • 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;
    });
    
    0 讨论(0)
提交回复
热议问题