简体   繁体   English

JavaScript 表单 Submit() 完成

[英]JavaScript Form Submit() Completion

Is there a way to call the javascript form submit() function or the JQuery $.submit() function and make sure that it completes the submit process?有没有办法调用 javascript 表单 submit() 函数或 JQuery $.submit() 函数并确保它完成提交过程? Specifically, within a form, I am trying to submit a form within an IFrame.具体来说,在表单中,我试图在 IFrame 中提交表单。 From the parent form, I am submitting the IFrame with the following code...在父表单中,我使用以下代码提交 IFrame...

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

The parent form then saves and closes.然后父窗体保存并关闭。 However, currently the IFrame is not completing the post before the parent form saves and closes.但是,目前 IFrame 在父表单保存和关闭之前没有完成帖子。 Is there any way using a JQuery callback or something in JavaScript to ensure this submit process completes before the parent form closes?有什么方法可以使用 JQuery 回调或 JavaScript 中的某些内容来确保在父表单关闭之前完成此提交过程?

Best what you can do is to submit the iframe's form asynchronously with help of jQuery Form plugin .您可以做的最好的事情是在jQuery Form plugin 的帮助下异步提交 iframe 的表单。 This way you can wait until the response is returned.这样您就可以等到响应返回。 It also provides a success callback handler which you can use to submit the parent page's form.它还提供了一个success回调处理程序,您可以使用它来提交父页面的表单。

<form onsubmit="return controlParentForm();" id="parentForm">
...
</form>

JS: 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;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM