Free javascript Hosting


applogin.js

Uploaded on Nov 21 2021 00:53 by ssinghi724

const InputUserName= document.querySelector('#UserName-value');
const InputPassword= document.querySelector('#Password-value');
const ButtonSubmit= document.querySelector('#btnSubmit');
ButtonSubmit.addEventListener('click',() =>{
    const enteredName= InputUserName.value;
    const enteredPassword= InputPassword.value;
   
    if(enteredName.trim().length<=0 || enteredPassword.trim().length<=0)
    {
        return;
    }
   //console.log(enteredName,enteredPassword);
   localStorage.setItem('username',enteredName);
   localStorage.setItem('password',enteredPassword);
    login()
   });
function login(){
    //username= "rtsuser";
    //password="Dell@123";
    let data = {
        "username": InputUserName.value,
        "password": InputPassword.value
    }
    url="http://ocijdeais.dcojdes.com:7081/jderest/tokenrequest";
    params={
        method :'POST',
        headers: {
            'Content-Type':'application/json',
           'Authorization':'Basic '+ btoa(`${InputUserName.value}:${InputPassword.value}`)

        },
        body: JSON.stringify(data)
    }
   /*fetch(url,params).then(response=> response.json())
    .then(json => console.log(json));
    */
    fetch(url,params).then(response=> {
       // console.log(response.ok);
        if(response.ok)
    {
        alert("Signed in Sucessfully")
        
            window.location = "option.html";   
    }
    else{
        alert("Please check your credentials")
    }
    });
  
}

Back to list