简体   繁体   English

取消form.submit()

[英]Cancel form.submit()

In javascript function I am submitin a form: 在javascript函数中,我以以下形式提交:
form.submit(); ,

with huge amount of data. 拥有大量数据

Is it possible to cancel this operation beside clicking on browser's stop button? 除了单击浏览器的停止按钮,是否可以取消此操作?

UPDATE: 更新:

Maybe i didn't made my self clear i am submiting large files. 也许我没有明确表示自己正在提交大文件。
form with uploadcontrol that runs in iframe. 在iframe中运行的带有uploadcontrol的表单。

You could do something like what Gmail does: Undo Sending Mails (lab feature). 您可以执行类似Gmail的操作:撤消发送邮件(实验室功能)。

It justs delays the mail sending by a 5 seconds. 它只是将邮件发送延迟了5秒钟。 If in that time the server receives a undo AJAX call, the mail is not send. 如果在那段时间内服务器收到undo AJAX呼叫,则不发送邮件。

This could potentially increase you serverside complexity, but not that much. 这可能会增加服务器端的复杂性,但幅度不大。

In the case that the information is not sent you could use this : 在未发送信息的情况下,您可以使用以下方法

//IE
document.execCommand('Stop');
//Firefox
window.stop();

So the whole thing would look something like this (pseudocode): 所以整个事情看起来像这样(伪代码):

stop_submit(current_id){
    try{
        document.execCommand('Stop');
    }catch(e){}
    try{
        window.stop();
    }catch(e){}

    AJAXCall("/myfolder/cancel_submit/", "id="+current_id, "post");
    return;
}

This is a classic problem with the client-server architecture. 这是客户端-服务器体系结构的经典问题。 Once the HTTP request has been made, there is no stopping it. 发出HTTP请求后,就无法停止它了。 You will need a way to restore state after all requests to guarantee that everything is back to the way it was. 在所有请求之后,您将需要一种恢复状态的方法,以确保一切恢复原状。

Now, you could do this with AJAX and use the abort function. 现在,您可以使用AJAX并使用abort功能。 Or, you could try window.stop() or document.execCommand("Stop") , depending on your browser. 或者,您可以尝试window.stop()document.execCommand("Stop") ,具体取决于您的浏览器。 But those do not solve the problem of the request having already been sent. 但是那些不能解决请求已经发送的问题。

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

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