Jquery and Django CSRF Token

前端 未结 3 896
礼貌的吻别
礼貌的吻别 2020-12-04 22:16

I have 2 html Pages.

A Parent Page and a Child Page. The Child Page Contains a Submit Button that runs code on the Parent Page to submit an Ajax message.

I

3条回答
  •  遥遥无期
    2020-12-04 22:51

    You are not passing the csrf token with POST. Try doing what I have done in data. That is to fetch the csrf token (or your own method) and pass it in your arguments.

    $.ajax({
        url : url,
        type: "POST",
        data : {csrfmiddlewaretoken: document.getElementsByName('csrfmiddlewaretoken')[0].value},
        dataType : "json",
        success: function( data ){
            // do something
        }
    });
    

提交回复
热议问题