1

ユーザーが ajax を介して投稿を削除できるようにしています。投稿には boolean フィールド live_until_removed があります。false に設定すると、投稿が非表示になります。

[削除] をクリックすると、次を参照して 403 が表示されます。

xhr.send( ( s.hasContent && s.data ) || null );

これをスムーズに実行するにはどうすればよいですか?なぜこのエラーが発生するのですか?

js:

$('#removeForm').submit(function() { // catch the form's submit event
    $.ajax({
        data: $(this).serialize(),
        type: $(this).attr('method'), 
        url: $(this).attr('action'),
        success: function(response) {
            $('.close-post').html(response); // update the DIV
            console.log(response);
        },
        error: function(response){
            console.log(response);
        }
    });
    return false;
});

テンプレート:

<div class="close-post">
     {% if not post.live_until_removed %}
     <form class="" id="removeForm" method="POST" action="">
          <button type="submit" class="btn">Remove</button>
     </form>
     {% else %}
     <button class="btn">Removed</button>
     {% endif %}
</div>

ビュー.py:

def post(request, id):
    ...
     if request.is_ajax():
          try: 
               post = Post.objects.get(id=id)
               post.live_until_removed = False
               post.save()
               response = simplejson.dumps({"status": "Removed"})
          except:
               pass
4

1 に答える 1

4

リクエストで CSRF トークンを送信しなかった可能性があります。ここを見てください。ジャンゴ・アヤックス

于 2013-04-25T20:14:14.463 に答える