Skip to content

Instantly share code, notes, and snippets.

@youngchief-btw
Last active August 17, 2020 01:34
Show Gist options
  • Save youngchief-btw/c1b82851f1a78f68681d1668cf7eba75 to your computer and use it in GitHub Desktop.
Save youngchief-btw/c1b82851f1a78f68681d1668cf7eba75 to your computer and use it in GitHub Desktop.
A function that does XMLHttpRequest handling and such
function XMLHttpRequestFUNC(method, url, async) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.response);
return;
}
};
xhr.open(method, url, async); // arguments[#]
// xhr.setRequestHeader("User-Agent", "https://youngchief-btw.github.io/"); // header, value
xhr.getAllResponseHeaders();
xhr.send();
}
// Usage Example:
// XMLHttpRequestFUNC("GET", "https://www.uuidgenerator.net/api/version4/500", true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment