Created
July 12, 2014 23:53
-
-
Save SecureCloud-biz/802a9f443338effb2332 to your computer and use it in GitHub Desktop.
Added CSRF token to AJAX calls using JavaScript Variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- 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