Django CSRF 403

前端 未结 1 525
情书的邮戳
情书的邮戳 2021-01-23 23:46

Getting a CSRF 403. The console.log statements below confirm that I\'m grabbing the token. I\'m submitting the request to the same domain on my local server.

          


        
相关标签:
1条回答
  • 2021-01-24 00:27

    not sure if this will help you. I had a similar problem. And fixed it by making a beforeSend functions that's add the X-CSRFToken

    $.ajax({
      url: url,
      data: JSON.stringify({'name': value }),
      type: 'POST',
      dataType: 'json',
      beforeSend: function (jqXHR, settings) {
        jqXHR.setRequestHeader('X-CSRFToken', $('input[name=csrfmiddlewaretoken]').val());
      },
      success: function(response) {
        alert("Success!");
      }
    })
    
    0 讨论(0)
提交回复
热议问题