Skip to content

Instantly share code, notes, and snippets.

@DmitriyShaydurov
Last active July 19, 2020 01:54
Show Gist options
  • Save DmitriyShaydurov/97abb4200785373587edb67538cbb1cb to your computer and use it in GitHub Desktop.
Save DmitriyShaydurov/97abb4200785373587edb67538cbb1cb to your computer and use it in GitHub Desktop.
// GET:
const Http = new XMLHttpRequest();
const url='http://example.com/';
Http.open("GET", url);
Http.send();
Http.onreadystatechange=(e)=>{
if (Http.readyState === 4) {
console.log(Http.responseText);
}
}
//POST:
var xhr = new XMLHttpRequest();
xhr.open("POST", '/user', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
var return_data = hr.responseText;
// Request finished. Do processing here.
}
}
xhr.send("name=Ipseeta&id=1");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment