我正在尝试使用 jquery 让我的表单保持在同一页面上。我使用名为 #clientUpdate-form 的表单,将其输入发布到 update.php。我尝试删除 window.location.href 并尝试将其更改为 window.location.href="edit_form.php?edit_id="+edit_id 但表单始终恢复为 index.php
完整代码:
/* Update Record */
$(document).on('submit', '#clientUpdate-form', function() {
$.post("update.php", $(this).serialize()).done(function(data) {
$("#dis").fadeOut();
$("#dis").fadeIn('slow', function() {
$("#dis").html('<div class="alert alert-info">' + data + '</div>');
$("#clientUpdate-form")[0].reset();
$("body").fadeOut('slow', function() {
$("body").fadeOut('slow');
window.location.href = "index.php";
});
});
});
return false;
});
/* Update Record */
最佳答案
您需要防止表单提交的默认事件。
$(document).on('submit', '#clientUpdate-form', function(e) { // note the e, thats the event
e.preventDefault(); // this stops the default event of the form
// then your stuff goes here
});
关于javascript - 提交表格并停留在同一页面上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35518488/