Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <!-- Disable JavaScript blockers in browser -->
- <script>
- var xhr;
- login("http://localhost:8080/login", "user", "userPass");
- function login(url, username, password) {
- xhr = new XMLHttpRequest();
- xhr.open("POST", url, true);
- xhr.onreadystatechange = onStateChange;
- xhr.onload = onSuccess;
- xhr.onerror = onError;
- xhr.send(getFormData(username, password));
- }
- function onSuccess() {
- var responseText = xhr.responseText;
- console.log('responseText:', responseText);
- }
- function onError() {
- console.log('There was an error!');
- }
- function onStateChange() {
- if (xhr.readyState === 4) {
- console.log('Status: ' + xhr.status);
- console.log('Response: ' + xhr.responseText);
- }
- }
- function getFormData(username, password) {
- var formData = new FormData();
- formData.append("username", username); // "username" must NOT be camel-case!
- formData.append("password", password); // "password" must NOT be camel-case!
- return formData;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement