第一:在HTML中加入{% csrf_token %}

$.ajax({
    url: '{% url "ceshi:list" %}',
    type: 'post',
    dataType: 'json',
    cache: false,
    data: {
        key: "11111",
        csrfmiddlewaretoken: $('[name="csrfmiddlewaretoken"]').val()
},

success: function(obj)
{
    console.log("hello")
}
});

第二:先在HTML中加入{% csrf_token %}

$.ajax({
    url: '{% url "ceshi:list" %}',
    type: 'post',
    dataType: 'json',
    cache: false,
    headers: {"X-CSRFToken": $('[name="csrfmiddlewaretoken"]').val()},
    data: {
        key: "11111",
    },

    success: function(obj)
    {
        console.log("hello")
    }
});

 

相关文章:

  • 2021-11-11
  • 2022-12-23
  • 2021-07-22
  • 2021-09-21
  • 2021-08-04
  • 2021-12-20
  • 2022-12-23
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2021-12-16
  • 2022-12-23
  • 2022-03-05
  • 2021-12-20
相关资源
相似解决方案