Implement easier way to retrieve CSRF token

This commit is contained in:
Koen Bolhuis 2018-10-09 22:12:41 +02:00
parent 45dc9e0fa8
commit b798898076
2 changed files with 2 additions and 17 deletions

View File

@ -162,7 +162,7 @@
<a class="btn btn-danger btn-sm" href="#" id="close-review-box" style="display:none; margin-right: 10px;"> <a class="btn btn-danger btn-sm" href="#" id="close-review-box" style="display:none; margin-right: 10px;">
<span class="glyphicon glyphicon-remove"></span>Cancel</a> <span class="glyphicon glyphicon-remove"></span>Cancel</a>
<input type="hidden" id="rating_input" name="rating" value="1"> <input type="hidden" id="rating_input" name="rating" value="1">
{% csrf_token %} <div id="csrf-token">{% csrf_token %}</div>
<input type="hidden" name="entity_id" value="{{ entity.pk }}"> <input type="hidden" name="entity_id" value="{{ entity.pk }}">
<button class="btn btn-success btn-lg" type="submit">Save</button> <button class="btn btn-success btn-lg" type="submit">Save</button>
</div> </div>

View File

@ -1,20 +1,5 @@
$(function() { $(function() {
function getCookie(name) { var csrftoken = $("#csrf-token input").val();
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// 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;
}
var csrftoken = getCookie('csrftoken');
$(".vote-up").click(function() { $(".vote-up").click(function() {
var reviewId = $(this).attr("data-review-id"); var reviewId = $(this).attr("data-review-id");