Implement easier way to retrieve CSRF token
This commit is contained in:
parent
45dc9e0fa8
commit
b798898076
|
@ -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>
|
||||||
|
|
|
@ -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");
|
||||||
|
|
Loading…
Reference in New Issue