ajax seems to work and we now seem to track completion of challenges

This commit is contained in:
Michael Q Larson
2014-11-06 22:47:35 -08:00
parent 86d433aaba
commit e36a98cf2a
3 changed files with 24 additions and 7 deletions

View File

@@ -1,29 +1,46 @@
$(document).ready(function() {
var CSRF_HEADER = 'X-CSRF-Token';
var setCSRFToken = function(securityToken) {
jQuery.ajaxPrefilter(function(options, _, xhr) {
if ( !xhr.crossDomain )
xhr.setRequestHeader(CSRF_HEADER, securityToken);
});
};
setCSRFToken($('meta[name="csrf-token"]').attr('content'));
$('.start-challenge').on("click", function() {
$(this).parent().remove();
$('.challenge-content').removeClass('hidden-element').addClass('animated fadeInDown');
});
$('.completed-challenge').on("click", function() {
$('#complete-dialog').modal('show');
});
$('.skip-challenge').on("click", function() {
$('#skip-dialog').modal('show');
});
$('.complete-button').on("click", function() {
l = location.pathname.split('/');
cn = l[l.length - 1]
$.ajax({
type: 'POST',
data: l,
url: '/completed_challenge',
data: {cn: cn},
url: '/completed_challenge/',
success: function(data) {
console.log('success');
console.log(JSON.stringify(data));
}
});
window.location = "/challenge?=" + (parseInt(l[l.length-1]) + 1)
window.location = "/challenges/" + (parseInt(l[l.length-1]) + 1)
});
$('.skip-button').on("click", function() {
l = location.pathname.split;
l = location.pathname.split('/');
window.location = "/challenges/" + (parseInt(l[l.length-1]) + 1)
});
});