Home >Web Front-end >Layui Tutorial >Why is layui form submitted twice?
(1) Generally, using layui results in two submissions. What comes to mind is that there is no return false when binding on sumit, which results in the regular submission method not being intercepted and accessed again. action
If you want to know more about layui. You can click: layui tutorial
form.on('submit(formDemo)', function (data) { var fd = new FormData($('form')[0]); $.ajax({ type: "POST", url: '/admin/adduser.do', data: fd, async: false, cache: false, contentType: false, processData: false, success: function (res) { if (res.status == 200) { layer.msg(res.msg, {time: 2000}); var url = "/admin/views/users.html"; // 跳转 setTimeout(function () { window.location.href = url },2000); } else { layer.msg(res.msg, {time: 2000}); } } }); return false; // 这段很关键 });
(2) However, my problem is not this. I visited the backend interface twice. It’s particularly strange. After debugging the front end, I found that layui.all.js was referenced one more time. That means the page was rendered twice, and of course it was submitted twice. <script src="../assets/layui.all.js"></script>
<script src="../assets/layui.all.js" charset="utf-8"></script>
<script src="../jquery.js"></script>
The above is the detailed content of Why is layui form submitted twice?. For more information, please follow other related articles on the PHP Chinese website!