Created
July 12, 2014 23:52
-
-
Save SecureCloud-biz/afdce5477ddbcb8eeb99 to your computer and use it in GitHub Desktop.
Added CSRF token to AJAX calls using Form Serialization
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
<!-- create form with open_form() --> | |
<form action="http://testapp.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