<button type=“submit”> with onclick submitti

2019-05-13 18:29发布

问题:

I am currently facing some order duplication issues. Without going into too much detail, I had a question about the following. Is there any possibility that this can trigger a submit twice?

<button type="submit" onclick="review.save()"></button>

review.save() will handle the submission of the form - so in fact the type=submit isn't needed here. But I want to establish whether this CAN cause the browser to submit twice. On the server logs the 2 submits were about 10 seconds apart.

回答1:

You need to prevent default browser behaviour, for example:

<button type="submit" onclick="review.save(); return false;"></button>


回答2:

Add a return false to your Button or better the 'oncklick' event!

Like:

<button type="submit" onclick="review.save();return false;"></button>

It "stops" the default browser behaviour of following links (in that case).

Edit: To slow :/