Last active
October 2, 2018 05:16
-
-
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
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
$.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