Skip to content

Instantly share code, notes, and snippets.

Last active Jan 3, 2016
What would you like to do?
Added CSRF token to AJAX calls using JavaScript Variable
<!-- add to HEAD -->
<script type="text/javascript">
var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
<!-- Update AJAX code, change csrf_test_name as needed -->
<script type="text/javascript">
$.post( ajax_url, { data: 'value', 'csrf_test_name': csrf_value }, function( response ) {
// response
}, 'json' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment