Skip to content

Instantly share code, notes, and snippets.

@athiththan11
Last active October 2, 2018 05:16
Show Gist options
  • Save athiththan11/85d86415e67c92f99f87be152f2131b0 to your computer and use it in GitHub Desktop.
Save athiththan11/85d86415e67c92f99f87be152f2131b0 to your computer and use it in GitHub Desktop.
CSRF Synchronizer Token Pattern | Ajax call request to retrieve the generated CSRF token from server
$.ajax({
url: 'serverURL',
type: 'post',
async: false,
data: {
'csrf_request': '<?php echo $_COOKIE['csrf_session_cookie'] ?>'
},
success: function (data) {
// appending the token to an hidden input field named csrf_token
document.getElementById("csrf_token").value = data;
$("#csrf_token_string").text(data);
},
error: function (xhr, ajaxOptions, thrownError) {
console.log("Error on Ajax call :: " + xhr.responseText);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment