且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Django 中使用 jQuery/Ajax 进行 POST?

更新时间:2022-06-26 07:49:15

Misplaced return false;.它应该在 .submit() 函数的末尾.所以将它向上移动一行:

Misplaced return false;. It should be at the end of .submit() function. So move it one line upwards:

$(document).ready(function () {
  $("#test").submit(function (event) {
    $.ajax({
      type: "POST",
      url: "/edit_favorites/",
      data: {
        'video': $('#test').val() // from form
      },
      success: function () {
        $('#message').html("<h2>Contact Form Submitted!</h2>")
      }
    });
    return false; //<---- move it here
  });

});

更新:

关于问题 POST/edit_favorites/HTTP/1.1" 403 2294.查看与您的问题类似的帖子:

About the issue POST /edit_favorites/ HTTP/1.1" 403 2294. Check on this post which looks similar to your issue: