提交Django表单时阻止页面刷新

时间:2020-05-25 23:38:44

标签: django django-forms

点击提交按钮后,有什么方法可以停止刷新表单页面吗?

我正在寻找使用javascript进行前端操作。

2 个答案:

答案 0 :(得分:0)

是可能的。 jQuery Ajax是个好主意

<filter **>
  @type grep
  <regexp>
    key message
    pattern /((- new_error:|- new_info:) & new_log)/
  </regexp>
</filter>

答案 1 :(得分:0)

我能够通过以下方式实现这一目标:

var formImage = $("#form_image");
formImage.submit(function (e) {
    e.preventDefault();
    var formData = new FormData(this);
    $.ajax({
        url: window.location.pathname,
        type: 'POST',
        data: formData,
        success: function (msg, status, jqXHR) {
            console.log(msg);
            console.log(status);
            console.log(jqXHR);
        },
        cache: false,
        contentType: false,
        processData: false
    });
});
相关问题