Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_forms_through_JavaScript
- function login() {
- console.log("Initiating Logon...");
- var username = document.getElementById("username").value;
- var password = document.getElementById("password").value;
- console.log("Got: "+username+" "+password);
- sendToMid(username,password);
- }//login
- async function postData(url, username, password) {
- // Default options are marked with *
- console.log("making fetch req");
- const response = await fetch(url, {
- method: 'POST', // *GET, POST, PUT, DELETE, etc.
- //mode: 'cors', // no-cors, *cors, same-origin
- //cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
- credentials: 'same-origin', // include, *same-origin, omit
- headers: {
- 'Content-Type': 'application/json'
- // 'Content-Type': 'application/x-www-form-urlencoded',
- },
- //redirect: 'follow', // manual, *follow, error
- //referrer: 'no-referrer', // no-referrer, *client
- body: JSON.stringify({ucid: username, pass: password}) // body data type must match "Content-Type" header
- }).catch(function (e) {
- console.log(e);
- });
- return await response.json(); // parses JSON response into native JavaScript objects
- }
- function sendToMid(username, password) {
- console.log("sendToMid...");
- // console.log(username);
- // console.log(password);
- console.log(JSON.stringify({ucid: username, pass: password}))
- const form = document.getElementById('login-form');
- console.log("send data");
- const response = await postData("myurl", username, password);
- console.log("got the following json: \n");
- console.log(response);
- var data = JSON.parse(response);
- console.log(data.itucid);
- console.log(data.itsuccess);
- }//sendToMid
- function showMessage(username, password) {
- console.log("showMessage");
- var msg = document.getElementById("response-msg");
- var loadmsg = document.createElement("p");
- loadmsg.innerHTML = 'Loading...';
- var msg_response = document.createElement("p")
- msg_response.innerHTML = username+" "+password;
- msg.appendChild(loadmsg);
- msg.appendChild(msg_response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement