页面可以静默发布多次

时间:2021-11-04 12:15:32

We're working in .net MVC and have a form to submit an email request. A user was on a very unstable internet connection (on an airplane) and claims that despite clicking the send button once, the form posted 6 times, resulting in 6 emails being sent. I've been looking around, but have not been able to find a way to explain that behavior. Is there any way for a posted form to submit multiple times due to a spotty connection?

我们正在.net MVC工作,并有一个表单来提交电子邮件请求。用户处于一个非常不稳定的互联网连接(在飞机上),并声称尽管单击发送按钮一次,表单发布了6次,导致发送了6封电子邮件。我一直在四处寻找,但未能找到解释这种行为的方法。由于连接不稳定,是否有任何方式可以使已发布的表单多次提交?

2 个解决方案

#1


2  

That would really depend on the actual browser, but I have yet to see one doing something like that (in fact, doing so would be dangerous, e.g. in the context of some online ordering service for example).

这实际上取决于实际的浏览器,但我还没有看到有人这样做(事实上,这样做会很危险,例如在一些在线订购服务的背景下)。

However, such things can happen by accident rather easily. Sometimes people aren't aware of multiple clicks, because they don't notice a first click triggering anything. It might happen that a browser doesn't immediately show any loading action/activity, especially with unstable connections. Also it's possible that due to some hardware problem (broken mouse button) multiple clicks are executed, despite only clicking once.

但是,这种事情很容易发生。有时人们不会发现多次点击,因为他们没有注意到第一次点击会触发任何内容。可能会发生浏览器没有立即显示任何加载操作/活动,特别是对于不稳定的连接。此外,由于某些硬件问题(鼠标按键损坏),可能会执行多次点击,尽管只需单击一次。

Just to be sure, I'd simply add some minimal JavaScript code to the form: On submit, disable the submit button and also avoid further attempts to send the form (intercept the onsubmit event and return true the first time; from there on always return false).

为了确保,我只需在表单中添加一些最小的JavaScript代码:在提交时,禁用提交按钮,并避免进一步尝试发送表单(拦截onsubmit事件并在第一次返回true;从那里始终返回false)。

#2


2  

I know I am late to answer but I faced similar problem and I believe the issue is with the browser. We use AJAX to submit form data to the controller and the processing takes a lot of time as the data to be processed is huge. Browsers like Chrome, wait for a certain time and if they do not receive a response, assume request is lost and send another request on it's own which is quite possibly the case on your end.Note that the same issue does not happen in browsers like Firefox and IE.

我知道我迟到了回答,但我遇到了类似的问题,我相信问题出在浏览器上。我们使用AJAX将表单数据提交给控制器,并且处理需要花费大量时间,因为要处理的数据非常庞大。浏览器如Chrome,等待一段时间,如果他们没有收到回复,则假设请求丢失并自行发送另一个请求,这很可能是你的结果。请注意,同样的问题不会发生在像Firefox和IE浏览器。

What we did to avoid that situation is to get the method work asynchronously and have the response back to the AJAX method within that interval of time to avoid Chrome from issuing a request again.

我们为避免这种情况所做的是让方法异步工作,并在该时间间隔内将响应返回给AJAX方法,以避免Chrome再次发出请求。

This link explains in detail the same issue.

此链接详细说明了同一问题。

#1


2  

That would really depend on the actual browser, but I have yet to see one doing something like that (in fact, doing so would be dangerous, e.g. in the context of some online ordering service for example).

这实际上取决于实际的浏览器,但我还没有看到有人这样做(事实上,这样做会很危险,例如在一些在线订购服务的背景下)。

However, such things can happen by accident rather easily. Sometimes people aren't aware of multiple clicks, because they don't notice a first click triggering anything. It might happen that a browser doesn't immediately show any loading action/activity, especially with unstable connections. Also it's possible that due to some hardware problem (broken mouse button) multiple clicks are executed, despite only clicking once.

但是,这种事情很容易发生。有时人们不会发现多次点击,因为他们没有注意到第一次点击会触发任何内容。可能会发生浏览器没有立即显示任何加载操作/活动,特别是对于不稳定的连接。此外,由于某些硬件问题(鼠标按键损坏),可能会执行多次点击,尽管只需单击一次。

Just to be sure, I'd simply add some minimal JavaScript code to the form: On submit, disable the submit button and also avoid further attempts to send the form (intercept the onsubmit event and return true the first time; from there on always return false).

为了确保,我只需在表单中添加一些最小的JavaScript代码:在提交时,禁用提交按钮,并避免进一步尝试发送表单(拦截onsubmit事件并在第一次返回true;从那里始终返回false)。

#2


2  

I know I am late to answer but I faced similar problem and I believe the issue is with the browser. We use AJAX to submit form data to the controller and the processing takes a lot of time as the data to be processed is huge. Browsers like Chrome, wait for a certain time and if they do not receive a response, assume request is lost and send another request on it's own which is quite possibly the case on your end.Note that the same issue does not happen in browsers like Firefox and IE.

我知道我迟到了回答,但我遇到了类似的问题,我相信问题出在浏览器上。我们使用AJAX将表单数据提交给控制器,并且处理需要花费大量时间,因为要处理的数据非常庞大。浏览器如Chrome,等待一段时间,如果他们没有收到回复,则假设请求丢失并自行发送另一个请求,这很可能是你的结果。请注意,同样的问题不会发生在像Firefox和IE浏览器。

What we did to avoid that situation is to get the method work asynchronously and have the response back to the AJAX method within that interval of time to avoid Chrome from issuing a request again.

我们为避免这种情况所做的是让方法异步工作,并在该时间间隔内将响应返回给AJAX方法,以避免Chrome再次发出请求。

This link explains in detail the same issue.

此链接详细说明了同一问题。