Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.