Last active
May 2, 2022 14:32
-
-
Save Scemist/30cd78636c71afa7ee7015cd93527e29 to your computer and use it in GitHub Desktop.
Elegant Ajax in JS with XMLHttpRequest
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
const xhr = new XMLHttpRequest() | |
xhr.open('GET', 'server.php') | |
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded ') | |
xhr.onreadystatechange = _ => { | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
console.log(xhr.responseText) | |
} else { | |
console.log('Loading') | |
} | |
} | |
xhr.send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment