javascript - 提交表格并停留在同一页面上?

标签 javascript php jquery

我正在尝试使用 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/

相关文章:

jquery - 设计 ajax 模态登录不适用于 Rails 5

javascript - Select2 val 不反射(reflect)选择顺序但对其进行排序

javascript - 使用 React Router v4 在身份验证后导航到页面

javascript - 我想通过 jQuery 使这个脚本实时运行,我该怎么做?

javascript - 无法用ajax重写一些html内容

javascript - 如何使用javascript访问隐藏按钮

php - Ilias 找不到目标类 ilcommonactiondispatchergui (ilrepositorygui)

php - 具有多个图像上传的动态文件名

javascript - Bootstrap - 提交文件输入表单?

jquery - CSS3 + jQuery 翻页时间调整