Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Last active January 3, 2016 00:59
Show Gist options
  • Save niraj-shah/8385848 to your computer and use it in GitHub Desktop.
Save niraj-shah/8385848 to your computer and use it in GitHub Desktop.
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(); ?>';
</script>
<!-- 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' );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment