Skip to content

Commit

Permalink
Merge remote-tracking branches 'teymour/configure_csrf' and 'teymour/…
Browse files Browse the repository at this point in the history
…ajax' into develop
  • Loading branch information
tienne-B committed Oct 31, 2024
2 parents 065a1af + 22d3202 commit 550d6af
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tabbycat/templates/ajax/AjaxMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,27 @@ export default {
) {
const self = this
const dataPayload = JSON.stringify(payload)
function getCookie (name) {
let cookieValue = null
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';')
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim()
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1))
break
}
}
}
return cookieValue
}
const csrftoken = getCookie('csrftoken')
$.ajax({
type: 'POST',
url: url,
headers: { 'X-CSRFToken': csrftoken },
mode: 'same-origin',
data: dataPayload,
contentType: 'application/json',
dataType: 'json',
Expand Down

0 comments on commit 550d6af

Please sign in to comment.