Home > Web Front-end > JS Tutorial > body text

How to solve the problem of Chrome Form submitting the form multiple times_javascript skills

WBOY
Release: 2016-05-16 18:06:50
Original
1483 people have browsed it

When I submitted a form using chrome today, I found a strange problem:

Copy code The code is as follows:

//Submit the form
document.frmOrder.action = 'http://www.abc.com/d.aspx';
document.frmOrder.method = 'POST';
document.frmOrder .target = '_blank';
document.frmOrder.submit();

The first submission is OK, but the second submission will not get any response. The page needs to be reloaded before submission, but this problem does not occur under Firefox and IE.
I immediately Googled and found that this is a common feature of webkit core browsers. This is done to prevent the form from being submitted repeatedly.

The solution is also very simple. You only need to add an onclick event response to the submit button, add a useless parameter to the form's action value, and change the form's response address.

Specific implementation method:
Copy code The code is as follows:

// Submit form
document.frmOrder.action = 'http://www.abc.com/d.aspx?r=' Math.random();
document.frmOrder.method = 'POST';
document.frmOrder.target = '_blank';
document.frmOrder.submit();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template