代码之家  ›  专栏  ›  技术社区  ›  SaaS Developer

JavaScript表单提交()完成

  •  1
  • SaaS Developer  · 技术社区  · 16 年前

    有没有办法调用javascript表单submit()函数或JQuery$.submit()函数,并确保它完成提交过程?具体来说,在表单中,我试图在IFrame中提交表单。从父窗体中,我正在提交带有以下代码的IFrame。。。

    document.frames.IFRAME_Items.document.forms[0].submit();
    

    然后,父窗体保存并关闭。但是,当前在父窗体保存并关闭之前,IFrame没有完成post。有没有办法使用JQuery回调或JavaScript中的某些东西来确保在父窗体关闭之前完成此提交过程?

    2 回复  |  直到 16 年前
        1
  •  1
  •   andres descalzo    16 年前
    <form onsubmit="return controlParentForm();" id="parentForm">
    ...
    </form>
    

    JS:

    var controlSubmitParentForm = 0;
    function controlParentForm(){
    
       var ret = false;
    
       if (controlSubmitParentForm==0){
    
         controlSubmitParentForm = 1;
         document.frames.IFRAME_Items.document.forms[0].submit();
         setTimeout(controlParentForm, 200);
    
       }
       else if (controlSubmitParentForm==1){
    
         if (document.frames.IFRAME_Items.document.readyState=="complete"){
            controlSubmitParentForm = 2;
            document.getElementById("parentForm").submit();
         }
         setTimeout(controlParentForm, 200);
    
       }
       else if (controlSubmitParentForm==2){
           // controls for "parentForm"
           ret = true;
           controlSubmitParentForm = 0;
       }
    
       return ret;
    
    }
    
        2
  •  1
  •   BalusC    16 年前

    您所能做的最好的事情是在 jQuery Form plugin . 这样,您就可以等待响应返回。它还提供了一个 success