简体   繁体   English

在已经开始后停止提交表单

[英]Stop form submission AFTER it has already been started

Is there a way to stop form submission AFTER it has already been started. 是否有一种方法可以在表单启动后停止提交。
Here is what I mean. 这就是我的意思。 I have a code like this: 我有这样的代码:

<form method="POST"
      action="/hell">
    <input type="text" name="filename">
    <input type="submit">
</form>

<script type="text/javascript">
    $('form').on('submit', function (event) {

        setTimeout(function () {
            // And here i need to stop the form submission process
        }, 1000);

    });
</script>

To simplify the example let's say that the form target page never answers faster than in couple seconds. 为了简化示例,我们假设表单目标页面的响应速度绝不会超过几秒钟。
What I really want to achieve here is something like non-ajax submission abortion. 我在这里真正想要实现的是诸如非ajax提交中止之类的东西。 Is it even possible? 可能吗

ADDED: 添加:
I'm trying to make a jQuery plugin (for some specific needs) and in order to send files with a form I use iframe to fake synchronous ajax request. 我正在尝试制作一个jQuery插件(出于某些特定需求),并且为了以某种形式发送文件,我使用iframe伪造了同步ajax请求。 But can't find a way to abort the submission on i timeout. 但是找不到在超时时中止提交的方法。
Yes, I'm aware of FormData (which is not suitable for me, I can sweep aside IE < 9, but IE 9 support is required), as well as about a bunch of plugins, which still use iframe under the hood (none of them can serve my needs). 是的,我知道FormData(不适合我,我可以将IE <9排除在外,但需要IE 9支持),以及大约一堆插件,这些插件仍在幕后使用iframe(无)它们可以满足我的需求)。

No, there isn't. 不,没有。 By the time the timeout function runs, the browser will have already submitted the form and be loading the new page. 到超时功能运行时,浏览器将已经提交表单并正在加载新页面。

If you want to cancel the submission conditionally than the closest you could come would be to always prevent the default form behaviour and then conditionally restart it (by calling submit() ) in the timeout. 如果要有条件地取消提交,而不是最接近的提交,则总是要防止默认表单行为,然后有条件地在超时(通过调用submit() )中重新启动它。

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

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