Created
April 1, 2015 10:12
-
-
Save mebjas/332718be6cbf2a26f8a2 to your computer and use it in GitHub Desktop.
Adding event listener to forms added via AJAX
This file contains 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
var formObj = document.getElementById('form-loaded-via-ajax'); | |
// ^^ Use any form of method to get the DOM object here | |
formObj.addEventListener("submit", function(event) { | |
if (typeof event.target[CSRFP.CSRFP_TOKEN] === 'undefined') { | |
event.target.appendChild(CSRFP._getInputElt()); | |
} else { | |
//modify token to latest value | |
event.target[CSRFP.CSRFP_TOKEN].value = CSRFP._getAuthKey(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment