Skip to content

Instantly share code, notes, and snippets.

@niraj-shah niraj-shah/ajax_csrf.html
Last active Jan 3, 2016

Embed
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(); ?>';
</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
You can’t perform that action at this time.