Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Created January 12, 2014 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niraj-shah/8385899 to your computer and use it in GitHub Desktop.
Save niraj-shah/8385899 to your computer and use it in GitHub Desktop.
Added CSRF token to AJAX calls using Form Serialization
<!-- create form with open_form() -->
<form action="http://testapplication.com/login" method="post" accept-charset="utf-8" id="login-form" class="login">
<div style="display:none">
<input type="hidden" name="csrf_test_name" value="80bfb80b356d6d31f4ce4dad0c6cf69e">
</div>
...
...
</form>
<!-- Update AJAX code to post serialized data -->
<script type="text/javascript">
$.post( ajax_url, $('#login-form').serialize(), function( response ) {
// response
}, 'json' );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment