Skip to content

Commit

Permalink
separate js form process
Browse files Browse the repository at this point in the history
  • Loading branch information
jdungan committed Apr 17, 2017
1 parent 98734f6 commit 3c617f1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions static/js/vote-app.js
@@ -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);
});

0 comments on commit 3c617f1

Please sign in to comment.