Skip to content

Instantly share code, notes, and snippets.

@kezzyhko
Created February 4, 2021 20:23
Show Gist options
  • Select an option

  • Save kezzyhko/6bc4ae3174306ae400c3e53953e8e359 to your computer and use it in GitHub Desktop.

Select an option

Save kezzyhko/6bc4ae3174306ae400c3e53953e8e359 to your computer and use it in GitHub Desktop.
JS code to make POST requests and rewrite current page to the response
request = new XMLHttpRequest();
request.open("POST", "http://example.com/", true);
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
request.onreadystatechange = function() {
if (request.readyState == 4) {
document.open();
document.write(request.responseText);
document.close();
console.log("done");
}
};
request.send("param=" + encodeURIComponent("value"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment