Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function make_submit_form (csrf_token){ | ||
return function (e) { | ||
e.preventDefault(); | ||
form = $(this) | ||
$.ajax( { | ||
url: form.attr('action'), | ||
method: form.data("method"), | ||
data: form.serialize(), | ||
processData: false, | ||
headers: {'X-CSRFToken': csrf_token}, | ||
contentType: 'application/x-www-form-urlencoded; charset=UTF-8', | ||
success: (data, textStatus, jqXHR) => window.location.reload(), | ||
error: console.error | ||
} | ||
); | ||
} | ||
} | ||
|
||
$(document).ready(function(){ | ||
// start foundation js | ||
$(document).foundation(); | ||
// set up generic ajax post to codesy | ||
const csrf_token_value = $('form input[name="csrfmiddlewaretoken"]').val() | ||
const submitForm = make_submit_form(csrf_token_value) | ||
$('form.vote-submit').submit(submitForm); | ||
}); |