<button type=“submit”> with onclick submitti

2019-05-13 18:17发布

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.

2条回答
迷人小祖宗
2楼-- · 2019-05-13 18:55

You need to prevent default browser behaviour, for example:

<button type="submit" onclick="review.save(); return false;"></button>
查看更多
Fickle 薄情
3楼-- · 2019-05-13 18:55

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 :/

查看更多
登录 后发表回答